- Home /
is there a way to make a object that you can pick up and when you do pick it up the object will teleport to a curtain location
Is there a way to make a object that you can pick up and when you do pick it up the object will teleport to a curtain location and when you collect a curtain amount of objects it will load another level?Thank you.
Answer by BokenArts · Jun 25, 2017 at 03:24 AM
If I understood right, To be able to pick up an object you could create a script and attach it to a pickable gameobject and there get the click, using Input.GetTouch inside Update() if it is for a mobile device or OnMouseUp if its not. Then inside any of those methods, to teleport to some location change the position of the camera or whatever you need to move by using gameobjectToMove.transform.position = new Vector3(xpos,ypos,zpos)
, and tell another script to update the number of picked up objects, for example counterScript.PickedUpObject()
the script could be attached to an empty gameobject and be like this:
using UnityEngine; using UnityEngine.SceneManagement; class CounterScript: MonoBehaviour {
private int count = 0;
private const int neededCount =5;
private const string sceneToLoad = "anotherLevel"
void Start(){
count = 0;
}
public void PickedUpObject() {
count ++;
if (count >= neededCount){
SceneManager.LoadScene(sceneToLoad, LoadSceneMode.Single);
}
}
}
Thanks! I will test it out once unity loads up i have monodevelop open but unity is still importing i hope it works!