Is the script you posted attached to an object with a tag ‘xxx’ and the same script is attached to an object with tag ‘yyy’ and you want to check if the player enters this collider and then does something based on the objects tag.
Sorry I took so long to reply I was eating some juicy roast chicken.
Will the objects tag change or will you create an object with a tag ‘lava’ and it will always be tagged as ‘lava’ ?
If the object will always have the same tag the just put a script on each object for example the lava could have lava.cs attached and workspace could have workspace.cs attached then each script can be written especially for that type of object.
What I do is create prefabs for objects and this allows you to alter and develop each object as its own seperate unit.
For example your lava could be a prefab with the lava model or sprite, its collider (set as is trigger) and the lava.cs.
Then for the script you would use something like:
using UnityEngine;
using System.Collections;
public class lava : MonoBehaviour
{
void OnTriggerStay(Collider col)
{
if(col.gameObject.tag == "Player")
{
// do whatever the lava does to the player such as reduce player health or shield
}
}
}
Then on the workspace object you would attach the workspace.cs script:
using UnityEngine;
using System.Collections;
public class workspace : MonoBehaviour
{
void OnTriggerStay(Collider col)
{
if(col.gameObject.tag == "Player")
{
// do whatever the workspace does to the player such as crafting or trading
}
}
}
Ah now i got what i want, turns out i needed to attach the script to the player and make a few mods, im very certain it will work…but it dosnt…it should be scripted correctly…and the collision trigger is ticked but not working…
void OnTriggerStay(Collider col){
Debug.Log("Enter");
if (col.gameObject.tag == "Item") {
Debug.Log ("This is an item!");
}
if (col.gameObject.tag == "Tree") {
Debug.Log ("This is a tree!");
}
if (col.gameObject.tag == "Smelt") {
Debug.Log ("This is a smeltery!");
}
I have made a custom made actor so i assume its to do with him/her