Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update(){
- Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; // subtracting the position of the player from the mouse mous position
- difference.Normalize(); // normalizing the vector. meaning that all the sum of the vector will be equal to 1
- float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; //find the angle in degrees
- transform.rotation = Quaternion.Euler(0f, 0f, rotZ );
- }
- void Update(){
- transform.Rotate(0, 0, -3.0f);
- }
- private int direction = 1;
- void Update(){
- if(transform.rotation.z == 0 || transform.rotation.z == 180){
- direction = -direction;
- }
- transform.Rotate(0,0,-3f*direction);
- }
- public class Turret {
- [SerializeField] private float _minEulerRotation;
- [SerializeField] private float _maxEulerRotation;
- [SerializeField] private float _rotationAmount;
- private CoolDown _coolDown;
- void Start(){
- this._rotationAmount *= Time.fixedDeltaTime;
- this.StartCoroutine(this.RotationProcess());
- }
- private IEnumerator RotationProcess()
- {
- while (true)
- {
- yield return this.StartCoroutine(this.RotateToMin());
- yield return this.StartCoroutine(this.RotateToMax());
- }
- }
- private IEnumerator RotateToMin()
- {
- while(transform.rotation.eulerAngles."Axis you need" > this._minEulerRotation){
- transform.Rotate("Your vector3" * this._rotationAmount);
- if(this._coolDown.IsActive)
- {
- yield return this._coolDown.Delay;
- }
- yield return null;
- }
- transform.rotation = Quaternion.Euler("Your vector3" * this._minEulerRotation);
- }
- private IEnumerator RotateToMax()
- {
- while(transform.rotation.eulerAngles."Axis you need" < this._maxEulerRotation){
- transform.Rotate("Your vector3" * this._rotationAmount);
- if(this._coolDown.IsActive)
- {
- yield return this._coolDown.Delay;
- }
- yield return null;
- }
- transform.rotation = Quaternion.Euler("Your vector3" * this._maxEulerRotation);
- }
- public void Shoot()
- {
- ...... some cooldown stuff
- this._coolDown.StartCountdown();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement