Jacobsc
1
So I have a 3d game with a player that consists of an empty object with three children, one black engine and two body parts that need to change color.
using UnityEngine;
using System.Collections;
public class Collection : MonoBehaviour
{
public Transform tForm;
public GameObject gObject;
private bool isGreen = false;
private bool isRed = false;
void OnTriggerEnter(Collider other)
{
//green
if (other.gameObject.tag == "GreenCube")
{
other.gameObject.SetActive(false);
isGreen = true;
}
//red
if (other.gameObject.tag == "RedCube")
{
other.gameObject.SetActive(false);
isRed = true;
}
}
private Color childColorGreen;
private Color childColorRed;
public void ChangeColor ()
{
childColorGreen = new Color(0, 0, 1, 1);
childColorRed = new Color(1, 0, 0, 1);
if (isGreen == true)
{
gObject.FindComponentsInChildren<Material.Color>() = childColorGreen;
}
if (isRed == true)
{
gObject.FindComponentsInChildren<Material.Color>() = childColorRed;
}
}
}
Also, how do I get specific child? I need two child from “Player;” I need “Body” and “Front.”
Try something like this…
transform.Find("Body").gameObject.GetComponent<Material>().Color = childColorGreen;
Same idea for Front.
-Larry