Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class BowCharge : MonoBehaviour
- {
- private Animation anim;
- private Rigidbody body;
- private GameObject arrowClone;
- public GameObject baseArrow;
- public GameObject activeArrow;
- public float power;
- void Start ()
- {
- anim = GetComponent<Animation> ();
- }
- void Update ()
- {
- if (Input.GetMouseButtonDown (0))
- {
- anim.Play ("Bow Pull Back");
- }
- else if (Input.GetMouseButtonUp (0))
- {
- anim.Play ("Bow Release");
- InstanciateArrow ();
- }
- if (body != null && arrowClone != null)
- {
- arrowClone.transform.right = -body.velocity.normalized;
- arrowClone.transform.LookAt (arrowClone.transform.position + body.velocity);
- }
- }
- private void InstanciateArrow()
- {
- arrowClone = Instantiate (baseArrow, activeArrow.transform.position, activeArrow.transform.rotation) as GameObject;
- arrowClone.gameObject.transform.position = activeArrow.transform.position;
- arrowClone.transform.rotation = activeArrow.transform.rotation;
- body = arrowClone.GetComponent<Rigidbody> ();
- body.useGravity = true;
- body.AddForce ((-transform.right) * (power * 10000) * Time.deltaTime, ForceMode.Impulse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement