I’ve tried looking it up, but I haven’t found anything that works. Please help! (Basically I just need the way to detect if a character has hit the object, and the object turning invisible would be nice for example :D)
EDIT
I tried both of your scripts, and nothing happened when I touched the cube. Here’s what I did by Aldonaletto. (I put it in the object named cube):
function OnTriggerEnter(Hit : Collider)
{
if(Hit.tag == "Player") // you can compare tags instead: if (Hit.tag = "Player")
{
renderer.enabled = false; // renderer alone is the trigger renderer
}
}
Here’s the one by DGArtistsInc, I put it in my character:
I think the problem might be that possibly there’s a character controller in the player. Also, I imported the mesh from Blender, and it has armatures in it. What’s my problem here?
EDIT
What’s wrong with this script?
function OnControllerColliderHit()
{
if(Hit.gameObject.Find("Cube"))
{
gameObject.Find("Cube").renderer.enabled = false;
}
}
I know that it’s probably because of there’s no parameters in the function.
The first two lines are completely unnecessary. The parameter Hit is a Collider, and allows direct access to most important object variables (properties), like name, tag, transform, renderer etc. If the cube is the trigger, and you want it to become invisible when touched by the player, attach this to the cube:
function OnTriggerEnter(Hit : Collider)
{
if(Hit.name == "Player") // you can compare tags instead: if (Hit.tag = "Player")
{
renderer.enabled = false; // renderer alone is the trigger renderer
}
}
u have to put rigidbody component on ur player and toggle Use Gravity to false and Is Kinematic to true and make the collider of the other object trigger … and put the script on ur player
I guess you could try instead of OnTriggerEnter you could try OnControllerColliderHit.
function OnControllerColliderHit()
{
if(Hit.gameObject.Find("name of your gameobject here"))
{
gameObject.Find("name of your gameobject here").renderer.enabled = false;
}
}
put this on your character. If that doesnt work i dont know whats wrong.
PS you dont have to make the cube isTrigger if you use this.
function OnTriggerEnter(Hit : Collider)
{
if(Hit.gameObject.Find(“name of your gameobject here”))
{
gameObject.Find(“name of your gameobject here”).renderer.enabled = false;
}
}
Try this then. I have no idea why the last one didnt work but this should work.