Video of Problem:
Note: This video only shows gameplay, which is where the problem exists. To see more about it, check my other post:
http://forum.unity3d.com/viewtopic.php?p=367562#367562
What you will notice:
Both boxes have a Collider on it, technically the box collider. One has its collider set as a trigger and the script corresponds with it, the other has colliders turned on and is NOT a trigger. Thus the script on this box has OnCollisionEnter instead.
The scripts are exactly the same, the only difference is that one has OnCollisionEnter and the other has OnTriggerEnter.
Ok, this is kind of hard to explain but here it goes. What I’m trying to do, is get an object to harm my player when my player touches that object… PROBLEM IS, that for some weird as #^$@ reason, my script isn’t sending the message “ApplyDamage” to my player script…
(This script grabs the target information, and applies damage, it’s got a bit of 2 scripts in here because even with a simple “Hey I collided with you!” script, it WILL NOT RUN
var target : Transform;
var damage = 1;
private var lastHitTime = 0.0;
// Cache link to player's state management script for later use.
function Start ()
{
if (!target)
target = GameObject.FindWithTag("Player").transform;
}
function OnCollisionEnter( col : Collision ) {
//if (Time.time > lastHitTime + 0.25 )
//{
if ( col.collider.tag == "Player" )
{
target.SendMessage("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);
//lastHitTime = Time.time;
}
//}
}
Using just this will not work (This is stripped to the bare essentials.
var target : Transform;
var damage = 1;
// Cache link to player's state management script for later use.
function Start ()
{
if (!target)
target = GameObject.FindWithTag("Player").transform;
}
function OnCollisionEnter( col : Collision )
{
target.SendMessage("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);
}
The script I’m using to react with? The Lerpz script of “Third Person Status”. I cannot get that code to send a a message. I’ve even changed the target.SendMessage to BroadcastMessage, moved the script to large and small targets, and still no reaction. No sound (I have sound confirmation), no change in values, nothing. The script refuses to send the message when I collide with it.
SOLVED
It took me another 4 hours, but it was finally solved. Turns out I needed “OnControllerColliderHit”, and I needed it slapped into my ThirdPersonWalker Script. Upon doing that, whenever I touch my “Enemy” I take damage… Now I need my character to bounce backwards, and I need my character to NOT take damage when I hop on an enemy (essentially destroying the enemy), but that’s another script.