- Home /
changing color on collision
Hi! it's my first time with the unity Answers and as you will see, I'm kinda new to unity itself. I'm at the learning process of understanding the basic of this great software.
So, as my first question, is there a way to change the color of a simple cube when the player collide with it, using the javascript?
I understand the principle of collision and the tag, I just need to know the "Script" err... command?
Thank you n_n
Answer by Lo0NuhtiK · Dec 29, 2011 at 02:01 PM
Attach this to the character controller object ->
var otherTag : String ; //assign in inspector the tag of the cube
// make sure you tag your cube also
var otherColor : Color ; //pick a color in the inspector to change the cube to
@HideInInspector
var controller : CharacterController ;
function Start(){
controller = GetComponent(CharacterController) ;
}
function OnControllerColliderHit(other : ControllerColliderHit){
if(other.gameObject.CompareTag(otherTag)){
other.gameObject.renderer.material.color = otherColor ;
}
}
Your answer
Follow this Question
Related Questions
How to fill the inside volume of a 3D mesh with color? 0 Answers
Physics.OverlapSphere() not working after using pool of objects 0 Answers
Ignore awake function call to destroy game object if character enters trigger 1 Answer
Collision Events - Executing Code once per Collision Across Multiple Objects 0 Answers