Reputation: 21
I'm doing a scrip for a game where the player goes over a stone and it changes color, when the color stays the desired color it will open a door. How do I compare GameObject color with the default color?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MudarCor : MonoBehaviour {
private Vector4[] cores = new Vector4[] {new Vector4(1, 0, 0, 1), new Vector4(0, 1, 0, 1), new Vector4(0, 0, 1, 1)};
public int cor;
public GameObject pedra1;
public GameObject pedra2;
public GameObject pedra3;
public Vector4[] teste= new Vector4[] { new Vector4(0, 1, 0, 1) };
private void Start() {
//define a cor inicial da pedra
gameObject.GetComponent<SpriteRenderer>().color = new Vector4(1, 0, 0, 1);
}
void OnTriggerEnter2D(Collider2D player)
{
if (cor == 2)
cor = 0;
else
cor++;
gameObject.GetComponent<SpriteRenderer>().color = cores[cor];
}
private void Update()
{
if (teste.Equals( pedra1.GetComponent<SpriteRenderer>().color))
{
//code
}
}
Upvotes: 0
Views: 35
Reputation: 23685
The basic way to do it is:
Color colorA = objA.GetComponent<SpriteRenderer>().color;
Color colorB = objB.GetComponent<SpriteRenderer>().color;
if (colorA.Equals(colorB))
....
Upvotes: 2