Question by
afurioso · 5 days ago ·
sceneobjectsbuttonsscene-change
Moving Objects through the scenes,Make all objects in a list clickable and move the selected object to another scene
Hi all, I am trying to make all objects in my object list placed in an empty GameObject, clickable.
I would like that when I click an object, that object only switches to another scene.
Could you help me make a single object clickable and move it to another scene?
I tried creating this script, but it doesn't work.
I appreciate any help you can provide.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
public class MovingObjects : MonoBehaviour
{
private RaycastHit hit;
// Type in the name of the Scene you would like to load in the Inspector
private string groundScene = "GroundScene";
private string airScene = "AirScene";
public GameObject gameObejctToMove;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.collider && gameObejctToMove == gameObject.CompareTag("GPobject"))
{
SceneManager.LoadScene(groundScene);
}
else if (hit.collider && gameObejctToMove == gameObject.CompareTag("MAobject"))
{
SceneManager.LoadScene(airScene);
}
}
}
}
}
,Hi all, I am trying to make all objects in my object list placed in an empty GameObject, clickable.
I would like that when I click an object, that object only switches to another scene.
Could you help me make a single object clickable and move it to another scene?
I tried creating this script, but it doesn't work.
I appreciate any help you can provide.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
public class MovingObjects : MonoBehaviour
{
private RaycastHit hit;
// Type in the name of the Scene you would like to load in the Inspector
private string groundScene = "GroundScene";
private string airScene = "AirScene";
public GameObject gameObejctToMove;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.collider && gameObejctToMove == gameObject.CompareTag("GPobject"))
{
SceneManager.LoadScene(groundScene);
}
else if (hit.collider && gameObejctToMove == gameObject.CompareTag("MAobject"))
{
SceneManager.LoadScene(airScene);
}
}
}
}
}
Comment