Check rotation of an obstacle
I've this code of an object that throws arrows: using UnityEngine; using System.Collections;
public class DispararFlechas : MonoBehaviour { public Transform Objeto; public float Seconds = 3; public GameObject DisparadorFlechas;
void Start () {
StartCoroutine(CoroutineShoot());
}
IEnumerator CoroutineShoot () {
while (true) {
Shoot();
yield return new WaitForSeconds(Seconds);
}
}
void Shoot () {
Instantiate(Objeto, transform.position, Quaternion.identity);
}
}
And this is the code of the arrows: using UnityEngine; using System.Collections;
public class Lanzamiento : MonoBehaviour {
public float velocidadLanzamiento;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Checar la rotacion en z, dependiendo a donde vea, es el Vector3 que utiliza
if(gameObject.transform.rotation.z == 90){
//hacia arriba
transform.Translate (new Vector3 (0, velocidadLanzamiento, 0));
}else if (gameObject.transform.rotation.z == 270) {
//hacia abajo
transform.Translate (new Vector3 (0, velocidadLanzamiento*-1, 0));
}else if(gameObject.transform.rotation.z == 180){
//izquierda
transform.Translate (new Vector3 (velocidadLanzamiento*-1, 0, 0));
}else {
//derecha
transform.Translate (new Vector3 (velocidadLanzamiento, 0, 0));
}
}
void OnBecameInvisible(){
Destroy (gameObject);
}
}
The problem I have is with the "if's", because I want that instead of checking the arrows rotation, I want to check the rotation of the object that throws them, and rotate the arrows depending on the rotation of the other object.
How can I do that?
Your answer
Follow this Question
Related Questions
Gun-recoil problem C# 0 Answers
Undesired Angles with transform.Rotate(...) 0 Answers
Problems With .rotate behavior 1 Answer
Cant stop object/ridgidbody from rotating 2 Answers
Auto level an object 0 Answers