Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. void Update ()
  2. {
  3. if (fireRate == 0)
  4. {
  5. if (CrossPlatformInputManager.GetButtonDown("Fire1"))
  6. {
  7. Shoot();
  8. }
  9. }
  10. else
  11. {
  12. if (CrossPlatformInputManager.GetButton ("Fire1") && Time.time > timeToFire)
  13. {
  14. timeToFire = Time.time + 1 / fireRate;
  15. Shoot();
  16. }
  17. }
  18. }
  19.  
  20. void Shoot ()
  21. {
  22. Vector2 joyStickPosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y);
  23. Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
  24. RaycastHit2D hit = Physics2D.Raycast (firePointPosition, joyStickPosition-firePointPosition, 100, whatToHit);
  25.  
  26. Debug.DrawLine(firePointPosition, (joyStickPosition - firePointPosition)*100, Color.cyan);
  27. if (hit.collider != null)
  28. {
  29. Debug.DrawLine(firePointPosition, hit.point, Color.red);
  30. Enemy enemy = hit.collider.GetComponent<Enemy>();
  31. if (enemy != null)
  32. {
  33. enemy.DamageEnemy(Damage);
  34. //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement