- Home /
I have to set a Collider[] to Collider - what do?
I have searched almost the entire Unity Answers for a similar questio. Unity script refference and google havent helped me either. But I get this really wierd error:
Script error: OnTriggerEnter This message parameter has to be of type: Collider The message will be ignored.
I'm sure this is a really easy fix, but I really have no clue how to fix it though.
here's a snippet of my code:
Edit: Well...the variable names might be a bit hard to understand. also I really suck at commenting while I write.
void OnTriggerEnter (Collider other)
{
if(other.transform.tag == "TriggerCube")
{
cubeScript = other.GetComponent<CubeStateScript>();
if(cubeScript.myColor == transform.tag)
{
//award The player with his points
scoreScript.points = scoreScript.points + maxScore;
}
else
{
other.renderer.material.shader = shader2;
delta = Time.timeSinceLevelLoad;
other1Gobject = other.gameObject;
other1Gobject.audio.Play();
other.rigidbody.useGravity = false;
other1 = other;
shaderChange = true;
otherParticle.emit = true;
}
}
}
void Update ()
{
if(shaderChange == true)
{
other1.renderer.material.SetFloat("_SliceAmount", 0.0f + Mathf.Lerp(0.0f , 1.0f, (Time.timeSinceLevelLoad - delta) *0.5f));
lightIntensity = other1.light.intensity;
other1.light.intensity = Mathf.Lerp(lightIntensity , 0.0f, (Time.time - delta) *0.5f);
if(other1.renderer.material.GetFloat("_SliceAmount") == 1.0f)
{
other1Gobject.collider.enabled = false;
other1Gobject.particleEmitter.emit = false;
cubeScript.waitTillIDie = true;
shaderChange = false;
}
}
}
Thanks
Answer by whydoidoit · Jun 13, 2012 at 10:15 PM
OnTriggerEnter is called multiple times (once for each collider hit) - it takes a single collider so drop your foreach loop and make the parameter of type Collider.
thanks for the answer but it didnt really fix the problem:
when one of the desired gameobjects hits my trigger, it works perfectly and it does what it has to do(the code above is just used as an example for easy read purposes). But when the first gameobject are undergoing its stuff, if I push another gameobject into the trigger. It cancels out the first "stuff-doing" sequence.
So all in all I need to make the script able to handle more than one collition at a time.
Tell me If you need the actual code :)
Well that would be helpful :) You have an error in the logic you are using for your processing, because OnTriggerEnter works the way I described...
Right so your problem is that you have multiple collisions and only one variable to handle it - the other1 stuff. It would make more sense to have the thing that works on the hit item be on the script of the hit item rather than trying to pull it over into this script.