HI, im very new to unity and i was wondering if i can change the colour of the object that my player is touching. So like i have a platform game and i would like each object the player walks over to change colour.
ok. it's easy to do in unity like many other things. soon you will learn much man!
there are two events that you can use. depending on the type of your collider you should use OnTriggerEnter or OnCollisionEnter events. if your platform is a trigger then either the platform or the player should have rigidbody attached (the rigidbody could be kinematic).
if it's a trigger you could attach this code to your platform.
this is a small C# example code that changes the color to myColor. you could declare it as a public var to be able to change the color in inspector. also you should set the player object's tag to "Player".
there are other ways that you can see who is the object collided with you. if it's a OnCollisionEnter event then the Collision object will be sent to your event and you should get it's .gameObject.tag to check it's tag.
most rendering and color/texture properties are in renderer.material.
you should either use a character controller or use rigidbodies to do it automatically or just code it yourself which i think you can not do at this time. in js just use function OnTriggerEnter (info : Collider) { //code }
what you wrote don't require the player tag because it does not have any if statements to check it. does your player have any colliders (trigger/not trigger) attached? if you don't want to fall then you should set isTrigger to off and use OnCollisionEnter instead.
you should either use a character controller or use rigidbodies to do it automatically or just code it yourself which i think you can not do at this time. in js just use function OnTriggerEnter (info : Collider) { //code }
– Ashkan_gcwhat you wrote don't require the player tag because it does not have any if statements to check it. does your player have any colliders (trigger/not trigger) attached? if you don't want to fall then you should set isTrigger to off and use OnCollisionEnter instead.
– Ashkan_gc