Question by
BrodyDaChappy · Jan 06, 2016 at 08:57 PM ·
2dcollisioncolorcolor change
Help Change Color of Object on Collide
Hi All,
I have been trying to figure out the script so that when my player Obj collides with platform Obj, the platform changes color instantly and stays that color, i have the below so far, any help please?
Many Thanks.
using UnityEngine; using System.Collections;
public class Colour : MonoBehaviour {
void OncollisionEnter2D(Collision2D col)
{
if(col.gameObject.tag == "Platform")
{
renderer.material.color = Color.cyan;
}
}
}
Comment
Answer by ZefanS · Jan 08, 2016 at 08:08 AM
Try this:
public class Colour : MonoBehaviour
{
void OncollisionEnter2D(Collision2D col)
{
if(col.gameObject.tag == "Platform")
{
col.gameObject.GetComponent<Renderer>().material.color = Color.cyan;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612055231im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to change material color for certain time? 1 Answer
Javascript 2D change color of spriteRenderer through script 1 Answer
Why is the tilemap color change messed up? 0 Answers
how to change object's B color when object A is in range? 2D 1 Answer
How to change the color of an object when it collides with another object? 2 Answers