- Home /
rigidbody woe ?
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
var score : Renderer;
function Start ()
{
}
function Update ()
{
transform.LookAt(Player);
if(Vector3.Distance(transform.position,Player.position) >= MinDist){
transform.position += transform.forward*MoveSpeed*Time.deltaTime;
if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
{
//Here Call any function U want Like Shoot at here or something
}
}
}
function OnColliderHit(collision:Collision){
if(collision.gameObject.tag == "bullet"){
print("hit");
score.enabled = true;
yield WaitForSeconds(2);
score.enabled = false;
}
}
I want it so when my bullet hits my enemy "score" pops up. Please help I've tried google and nothing.
No, it seems like they don't even collide but they do since my bullet pushes the enemies rigidbody back
Does the enemy have a rigidbody?
OnCollision[event] applies to things with colliders on rigidbodies, OnTrigger[event] is used on things without but I'm fairly sure you have to have the 'trigger' bit on, but you may need to do some other things if you have a collider set to be a trigger.
EDIT: Just read that you do have a rigidbody on it, sorry.
Answer by robertbu · Sep 26, 2013 at 01:03 AM
I've never heard of OnColliderHit(). Change it to OnCollisionEnter().
This doesn't work either
function OnCollisionEnter (other:Collider){
if (other.gameObject.tag == "bullet"){
print("hit");
Destroy (gameObject);
}
}
Doesn't work meaning you still don't see "hit" in your log?
Try adding Debug.Log("Test");
inside the function above your if
statement. Does that appear?
Also, isn't the argument supposed to be Collision
rather than Collider
? http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html
Changing the argument to Collision fixed it. Thank you to everyone who helped!! (=
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Pause Menu background problem 0 Answers
Shooting and changing bullet 1 Answer
Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers
JavaScript: GUI Box help 1 Answer