Advertisement
Guest User

Untitled

a guest
Dec 24th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NewTowerMovement : MonoBehaviour
  6. {
  7.     private Vector3 zAngle;
  8.     private float angle = 1.0f;
  9.  
  10.     // Update is called once per frame
  11.     void Update()
  12.     {
  13.         Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  14.         mousePos.z = 0f;
  15.  
  16.         Vector3 aimDirection = (mousePos - transform.position).normalized;
  17.         angle = (Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg) - 90;
  18.         zAngle = (new Vector3(0, 0, angle));
  19.         transform.eulerAngles = zAngle;
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement