Question by
Julinho314 · May 31, 2017 at 12:23 AM ·
c#instantiateplayertowards
Enemy Spawns Projectile towards player
I want to make a boss patern with a corrotine, but i cant make the boss to spawn a clone of a rock prefab towards player. Sorry for my english, i know its not great :s
public class BossScript : MonoBehaviour {
Player player;
public GameObject rock;
Rigidbody2D rigidBody;
public int velocity;
Rock spawn;
Rigidbody2D rockRigidBody;
// Use this for initialization
void Start ()
{
spawn = gameObject.GetComponent<Rock>();
player = gameObject.GetComponent<Player>();
StartCoroutine(Patern());
rigidBody = GetComponent<Rigidbody2D>();
rock = GetComponent<GameObject>();
rockRigidBody = rock.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
IEnumerator Patern()
{
yield return new WaitForSeconds(2);
rigidBody.velocity = new Vector2(velocity * -1, 0.0f);
yield return new WaitForSeconds(3);
rigidBody.velocity = new Vector2(0.0f, 0.0f);
yield return null;
Rigidbody2D clone;
clone = (Instantiate(rockRigidBody, transform.position + 1.0f * transform.forward, transform.rotation) as Rigidbody2D);
clone.AddRelativeForce(new Vector2(1000, 0));
}
}
Comment
i also have the rock added to the public section of the script.