Created
April 16, 2021 07:20
-
-
Save GT3000/31d5ea2587c135d579976e0aaf7f2859 to your computer and use it in GitHub Desktop.
Simple Color Change Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ChangeColor : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
private void OnCollisionEnter(Collision other) | |
{ | |
//When the player object hits this gameObject change it red | |
if (other.gameObject.GetComponent<Player>()) | |
{ | |
GetComponent<MeshRenderer>().material.SetColor("_Color", Color.red); | |
} | |
//When another gameObject like this one hits this one, turn it green | |
if (other.gameObject.GetComponent<ChangeColor>()) | |
{ | |
GetComponent<MeshRenderer>().material.SetColor("_Color", Color.green); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment