Advertisement
Vladkiber

Untitled

Mar 29th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Crossbow : MonoBehaviour
  7. {
  8. public float offset;
  9.  
  10. public GameObject ammo;
  11. public Transform shotDir;
  12.  
  13. private float timeShot;
  14. public float startTime;
  15.  
  16. public Joystick joystick;
  17.  
  18. void Start()
  19. {
  20.  
  21. }
  22.  
  23. void Update()
  24. {
  25. Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
  26. float rotateZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
  27. transform.rotation = Quaternion.Euler(0f, 0f, rotateZ + offset);
  28.  
  29. if (timeShot <= 0)
  30. {
  31. if (Input.GetMouseButtonDown(0))
  32. {
  33. Instantiate(ammo, shotDir.position, transform.rotation);
  34. timeShot = startTime;
  35. }
  36. }
  37. else
  38. {
  39. timeShot -= Time.deltaTime;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement