Quantcast
Channel: Answers by "MithosAnnar"
Viewing all articles
Browse latest Browse all 42

Answer by MithosAnnar

$
0
0
It took me bloody ages but i finally did it!! Here it is for anyone who wants to fire an arrow properly. make a plane with an archer sprite and animation script on him. put an attack script on the archer (just make sure you record the mouse position, so you can send it to your arrow script). on the arrow script put the following: ArrowScript.cs using UnityEngine; using System.Collections; public class Arrow : MonoBehaviour { public float damage = 5; public float rotationSpeed; public float arrowSpeed = 5; private Transform myTransform; private Vector3 mousePoint; private bool canTranslate = true; private bool canRotate = false; void ArrowStart (Vector3 v) { myTransform = transform; mousePoint = v; if (mousePoint.y > 200) { myTransform.rotation = Quaternion.Euler(0, 150, 0); rotationSpeed = Random.Range(2.5f, 5f); StartCoroutine("CanRotate", Random.Range(0.25f, 0.5f)); } if (mousePoint.y > 100 && mousePoint.y < 200) { myTransform.rotation = Quaternion.Euler(0, 170, 0); rotationSpeed = Random.Range(4f, 8f); StartCoroutine("CanRotate", Random.Range(0.15f, 0.3f)); } if (mousePoint.y < 100) { myTransform.rotation = Quaternion.Euler(0, 200, 0); rotationSpeed = Random.Range(20f, 40f); StartCoroutine("CanRotate", Random.Range(0.05f, 0.1f)); } } void Update () { if (canRotate == true) { myTransform.Rotate (0, (mousePoint.y / 10) * Time.deltaTime * rotationSpeed, 0); } if (canTranslate == true) { myTransform.Translate(new Vector3(-1, 0, 0) * arrowSpeed * Time.deltaTime); } if (myTransform.position.z <= - 2.2f) { StartCoroutine("Destroy"); } } IEnumerator Destroy () { canTranslate = false; canRotate = false; yield return new WaitForSeconds (2); Destroy(gameObject); } IEnumerator CanRotate (float f) { yield return new WaitForSeconds (f); canRotate = true; yield return new WaitForSeconds (f * 2); canRotate = false; } } Special thanks to Berenger for helping me!

Viewing all articles
Browse latest Browse all 42

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>