Reputation: 51
So I have 2 objects on my imageTarget and i added a box collider to both of them. I also added a different tag to them. I want it so that if you click on one of them it brings you to a different scene with info about that object. This is my code:
using System.Collections;using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using System.IO;
public class ObjectInfo : MonoBehaviour
{
public GameObject Eagle;
public GameObject LibertyStatue;
// Use this for initialization
void Start ()
{
Eagle = GameObject.Find ("Eagle");
LibertyStatue= GameObject.Find ("LibertyStatue");
//Eagle.SetActive (true);
//LibertyStatue.SetActive (true);
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if(hit.collider.tag == "Eagle");
{
ChangeScene ("EagleInfoScene");
}
if(hit.collider.tag == "LibertyStatue");
{
ChangeScene ("LibertyStatueInfoScene");
}
}
}
}
public void ChangeScene (string a)
{
Application.LoadLevel (a);
}
}
When i first added only one of the objects it worked fine, now after adding a new object and a new scene, both objects change to the new scene. So clicking both the eagle and liberty statue changes the scene to LibertyStatueInfoScene. Is there a way to fix this?
Solved: Wow im really stupid, the issue was that i had semicolons after my if statements, it didn't give me an error so i never noticed it.
Upvotes: 0
Views: 111
Reputation: 51
Solution: I didnt notice the semicolons after the if statements, removing them solves it. Strangely it didn't give me an error.
Upvotes: 1