Advertisement
crystalguy123

Untitled

Jan 30th, 2020
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Weapon : MonoBehaviour
  6. {
  7. public GameObject projectile;
  8. public Transform shotPoint;
  9. public float timeBetweenShots;
  10. private float shotTime;
  11.  
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15.  
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
  22. float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
  23. Quaternion rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
  24. transform.rotation = rotation;
  25.  
  26. if(Input.GetMouseButton(0))
  27. if (Time.time >= shotTime)
  28. {
  29. Instantiate(projectile,shotPoint.position, transform.rotation);
  30. shotTime = Time.time + timeBetweenShots;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement