Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BowCharge : MonoBehaviour
  5. {
  6.  
  7. private Animation anim;
  8. private Rigidbody body;
  9. private GameObject arrowClone;
  10.  
  11. public GameObject baseArrow;
  12. public GameObject activeArrow;
  13. public float power;
  14.  
  15. void Start ()
  16. {
  17. anim = GetComponent<Animation> ();
  18. }
  19.  
  20. void Update ()
  21. {
  22. if (Input.GetMouseButtonDown (0))
  23. {
  24. anim.Play ("Bow Pull Back");
  25. }
  26. else if (Input.GetMouseButtonUp (0))
  27. {
  28. anim.Play ("Bow Release");
  29. InstanciateArrow ();
  30. }
  31.  
  32. if (body != null && arrowClone != null)
  33. {
  34. arrowClone.transform.right = -body.velocity.normalized;
  35. arrowClone.transform.LookAt (arrowClone.transform.position + body.velocity);
  36. }
  37. }
  38.  
  39. private void InstanciateArrow()
  40. {
  41. arrowClone = Instantiate (baseArrow, activeArrow.transform.position, activeArrow.transform.rotation) as GameObject;
  42. arrowClone.gameObject.transform.position = activeArrow.transform.position;
  43. arrowClone.transform.rotation = activeArrow.transform.rotation;
  44. body = arrowClone.GetComponent<Rigidbody> ();
  45. body.useGravity = true;
  46. body.AddForce ((-transform.right) * (power * 10000) * Time.deltaTime, ForceMode.Impulse);
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement