hello
I want that an object is instantiated when i press Q
right now i have this for that
using UnityEngine;
using System.Collections;
public class kleidoufschieten : MonoBehaviour {
public Rigidbody projectile;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.Q))
{
Vector3 euler = transform.eulerAngles;
euler.x = 330 + Random.Range(0, 3) * 5;
transform.eulerAngles = euler;
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * 24);
}
}
}
this script is on the emty gameobject where the projectile shoots from. When i press Q it first rotates the object on the x axes and then shoots it.
But now i want to add another empty gameobject where it can shoot from. so when i press Q it picks an object random and then shoots that from it. So for example one empty gameobject is from the left and one is from the right.
That when i press Q it needs to sometimes do left right right left etc.
but it also needs to give it a rotatoin so the:
Vector3 euler = transform.eulerAngles;
euler.x = 330 + Random.Range(0, 3) * 5;
but how do i do that?
hope someone can help