Question by
SlappyTheMonkeyBoy · Nov 03, 2019 at 06:41 PM ·
other script
I have a Match up game with 10 items, when you place the right item in the right spot the plate turns green, when all 10 items are match up correctly I want to "do" something I have the 2 following scripts. please help.
First : this is the match up scripts works find.
using UnityEngine;
public class sampleCorrect : MonoBehaviour {
public Material[] material;
Renderer rend;
public GameObject rock;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
rend.sharedMaterial = material[0];
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag =="rock1")
{
rend.sharedMaterial = material[1];
}
else
{
rend.sharedMaterial = material[2];
}
}
void OnCollisionExit(Collision collision)
{
rend.sharedMaterial = material[0];
}
}
This is the second part I'm having issues with. once all 10 items are matched up and the material is [1] I want to do something.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MatchupCompleted : MonoBehaviour { public enum material { wood =0, green = 1 ,red=2};
public GameObject rock1;
public GameObject rock2;
public GameObject rock3;
public GameObject rock4;
public GameObject rock5;
public GameObject rock6;
public GameObject rock7;
public GameObject rock8;
public GameObject rock9;
public GameObject rock10;
private void Start()
{
}
void OnTriggerEnter(Collider other)
{
if (rock1.GetComponent<sampleCorrect>().GetComponent<Renderer> ().material = [1])
{
Debug.Log("yes");
}
}
}
but this is not correct please help. thank you
Comment
I know i will cascade the if statements for the following items, but need to get the first if statement correct.
Answer by SlappyTheMonkeyBoy · Nov 05, 2019 at 08:39 PM
Solved it. .shareMaterial == green; created an empty Object o hold script