Advertisement
jamieTheCoder

AimWeaponAtGameObject

Oct 21st, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using MoreMountains.CorgiEngine;
  5. using MoreMountains.Tools;
  6. public class AimWeaponAtGameObject : MonoBehaviour
  7. {
  8.     [SerializeField] WeaponAim weaponAim;
  9.     public GameObject aimObj;
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         weaponAim = GetComponent<WeaponAim>();
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     {
  19.         // this function does some math based on the transform of the gun
  20.         //which is a parent of the enemy so we need to translate the players position to account with that;
  21.         Vector3 aimVector = transform.InverseTransformPoint(aimObj.transform.position);
  22.         weaponAim.SetCurrentAim(aimVector);
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement