Anonim_999

GovnokodPushki

Sep 17th, 2024
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class CannonMovement : MonoBehaviour
  8. {
  9.     [SerializeField] private float _sensetivity = 90f;
  10.    
  11.     private void Update()
  12.     {
  13.         if (Input.GetMouseButton(0))
  14.         {
  15.            
  16.             Vector3 mousePosition = Input.mousePosition;
  17.             Vector3 CannonPosition = Camera.main.WorldToScreenPoint(transform.position);
  18.             Vector3 direction = (CannonPosition - mousePosition).normalized;
  19.             direction.x *= -1;
  20.             transform.LookAt(-direction * _sensetivity);
  21.             transform.Rotate(0,180,0,Space.World);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment