#4 gna
Nejako sa mi to podarilo podľa príkladu upraviť. A ešte otázka, že keď vojdem do izby, ako sa dá zistiť či daný objekt sa v miestnosti nachádza alebo sa nenachádza napr. pomenujeme modravaza.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class TriggerTest : MonoBehaviour {
private bool guitex=false ;
private bool guitexkuchyna=false;
private bool guitexchodba=false;
private bool guitexbyt=false;
void FixedUpdate()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, 10))
print("There is something in front of the object!");
}
void Start () {
}
// Update is called once per frame
void Update () {
}
// private Color m_oldColor=Color.red;
void OnTriggerEnter(Collider coln)
{
if(coln.tag == "obyvacka2" ){
guitex = true;
guitexkuchyna=false;
Renderer render=GetComponent<Renderer>();
// m_oldColor= render.material.color ;
render.material.color=Color.green;
}else if(coln.tag == "kuchyna"){
Renderer render=GetComponent<Renderer>();
// m_oldColor= render.material.color ;
render.material.color=Color.blue;
guitex = false;
guitexkuchyna=true;
}else if(coln.tag == "chodba"){
guitex = false;
guitexkuchyna=false;
guitexchodba=true;
}else if(coln.tag == "byt"){
guitex = false;
guitexkuchyna=false;
guitexbyt=true;
}
}
void OnTriggerExit(Collider coln)
{ guitex = false;
guitexkuchyna=false;
guitexchodba=false;
guitexbyt=false;
if(coln.tag == "obyvacka2"){
Renderer render=GetComponent<Renderer>();
render.material.color=Color.red;
}
}
private GUIStyle guiStyle = new GUIStyle(); //create a new variable
void OnGUI() {
if (guitex == true )
{
// GUI.contentColor = Color.yellow; //zmena farba textu
guiStyle.normal.textColor = Color.yellow;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do obyvacky",guiStyle);
}else if(guitexkuchyna==true){
guiStyle.normal.textColor = Color.yellow;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do kuchyne",guiStyle);
guitex =false;
}else if( guitexchodba==true){
guitex =false;
guiStyle.normal.textColor = Color.blue;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do chodby",guiStyle);
}else if( guitexbyt==true){
guitex =false;guitexchodba=false;guitexbyt=true;
GUI.Label(new Rect(255, 220, 190, 100), "vosiel som do bytu",guiStyle);
}else{
guiStyle.normal.textColor = Color.red;//farba hlasky
guiStyle.fontSize = 20; //change the font size
GUI.Label(new Rect(255, 220, 190, 100), "", guiStyle);
}
}
}