Skip to content

Instantly share code, notes, and snippets.

@GT3000
Created April 16, 2021 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GT3000/31d5ea2587c135d579976e0aaf7f2859 to your computer and use it in GitHub Desktop.
Save GT3000/31d5ea2587c135d579976e0aaf7f2859 to your computer and use it in GitHub Desktop.
Simple Color Change Script
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