I am working on a side scroller game. you can run around, jump, pick up crates, and stuff like that. What I am having trouble on is making enemies. I want it to be kinda like Braid, or Mario, enemies go back and forth and if you get hit by one you die, but if you jump on it’s head it dies. I have the AI enemy script, but I can’t make it die, or kill you. PLEASE HELP!
I prefer JavaScript, but if you can do it in C# or any other kind that is good too.
Here’s my enemy AI script
var pointB : Vector3;
function Start () {
var pointA = transform.position;
while (true) {
yield MoveObject(transform, pointA, pointB, 3.0);
yield MoveObject(transform, pointB, pointA, 3.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
and here is my character respawn script
static var dead = false;
function Update()
{
//if you die you respawn in same level
if(dead)
{
Application.LoadLevel(Application.loadedLevel);
}
//if you fall out of level you respawn
if(transform.position.y < -25)
{
Application.LoadLevel(Application.loadedLevel);
}
}
function OnCollisionEnter(hit : Collision)
{
//if you hit the enemy you die
if(hit.gameObject.tag == ("Enemy"))
{
dead = true;
}
}