SetActive switches objects from other scripts
Hi,
i am trying a quite simple thing, i have a map with POI-Objects and whenever i click on one i want some extra information to be displayed. Now i put the following script on all POI-Objects, everyone gets different GameObjects in the editor. i put in debug messages and from debugging everything looks like anticipated. Only all the GameObjects are being set active / set inactive at once, not only the one that is being hit by the raycast.
I seems to be in a stupid-loop, has anyone a hint how to get out?
Using Unity 2017.1.0f3 and deploying to iOS11 via xCode9.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Tap_Catcher : MonoBehaviour
{
public GameObject Lamp;
public GameObject TextCanvas;
private RaycastHit hit;
void Start()
{
TextCanvas.SetActive(false);
}
void Update()
{
if( Input.touchCount ==1)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
if (Physics.Raycast(ray, out hit, 1.0f))
{
if (hit.transform.gameObject == Lamp)
Debug.Log("Lamp hit: "+ hit.transform.gameObject);
{
if (TextCanvas.activeSelf == true)
{
TextCanvas.SetActive(false);
}
else
{
if (TextCanvas.activeSelf == false)
{
TextCanvas.SetActive(true);
}
}
}
}
}
}
}
}
Your answer
Follow this Question
Related Questions
how to display object while ! raycast hit is true ? 2 Answers
Touching anywhere on screen the Bow is releasing the arrow 1 Answer
raycasthit to set new move location 0 Answers
Raycast hit.point differs from Ray direction [SOLVED] 1 Answer
Dynamic Placement of Object Instantiate using RaycastHit 2 Answers