- Home /
How to make a system that will let elements interact with other elements?
I already have the hand states setup now but I need to get them working with other things in the scene. Like ice is melted when the fire hand comes near it, when ice is near water it freezes etc.
Answer by GregoryFenn · May 03, 2020 at 01:34 PM
One way is something like this:
void Update()
{
if ((firehand.transform.position - ice.transform.position).sqrMagnitude < 0.1f)
{
StartCoroutine(MeltingIce());
}
}
and you define the MeltingIce IEnumerator someway else in the file.
Or you could use an animation system, so instead do something like this:
void Update()
{
if ((firehand.transform.position - ice.transform.position).sqrMagnitude < 0.1f)
{
ice.gameObject.GetComponent<Animator>().SetTrigger("melting");
}
}
Just a couple of ideas
What would the coroutine be defined as? Good idea though, I came up with this not sure how to put it into practice.
[System.Serializable]
public class Element
{
public string name;
public GameObject prefab;
}
public class ElementInteraction : $$anonymous$$onoBehaviour
{
// Not the hand changing elements, the prefabs of the water for example.
public Element[] elementPrefabs;
private void Start()
{
}
private void OnTriggerEnter(Collider other)
{
foreach (var e in elementPrefabs)
{
if (other.gameObject == e.prefab)
{
}
}
}
}
Your answer
Follow this Question
Related Questions
OnCollisionEnter not being called while changing (unity Physics System) Gravity Value 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
RigidBody.MovePosition seems jerky in movement 0 Answers
Receiving UDP data in Unity? 0 Answers