- Home /
mario like cannon
Hi I wanted to make cannon like in Mario Bros. Right now it shoots bullets. I have 4-second looped animation so the bullet restarts in the cannon efter hitting the wall. So here comes the problem, bullet can either hit me and be destroyed or go through me, hit the wall and restart in cannon. I want it to hit me and then restart in the cannon.
My code so far:
#pragma strict
var bullet : GameObject;
var effect : Transform;
function OnTriggerEnter ()
{
Destroy(bullet);
Instantiate(effect, transform.position, transform.rotation);
}
function Update () {
}
Answer by xxBarginsxx · Jan 19, 2015 at 03:24 AM
I good way to do this is this.
(sorry, this is C#. C$ is the only thing I'm famillier with :))
public GameObject bullet;
public Transform effect;
void OnTriggerEnter(Collider colT)
{
if (colT.tag == "Mario")
{
Destroy(this);
Instantiate(effect, transform.position, transform.rotation);
}
else if (colT.tag == "Wall")
{
Destroy(this);
Instantiate(effect, transform.position, transform.rotation);
}
else
{
return;
}
}
void Update()
{
}
Thanks, I already did it my way. Just made animation stop and start from beggining.
Your answer
Follow this Question
Related Questions
bullets kill all enemies, not just the ones hit. 1 Answer
How to destroy bullet upon colliding with another object instead of bouncing off of it 3 Answers
Ammo Pickup 0 Answers
Bullets collide with a Trigger 2 Answers
My bullet script doens't work. 1 Answer