c# - Spawning Player at certain Point in Unity -


i making small 2d click'n'point in unity, , want is: want move towards door , when player steps on game object attached sceneswitcher script shall go through door, scene. works fine far. don't want him appear in middle of room, on door, entered room.

using unityengine;  using system.collections;  using pixelcrushers.dialoguesystem;  public class scenswitcher : monobehaviour {   public string scenename = "";   void ontriggerenter2d(collider2d other) {      switchscene();  }   void switchscene(){      levelmanager levelmanager = dialoguemanager.instance.getcomponent<levelmanager>();      levelmanager.loadlevel (scenename);      changeposition ();      debug.log ("scene wechseln nach: " + scenename);  }  void changeposition(){      gameobject player = gameobject.find("player");      player.transform.position = new vector3(12,12,0);  }  } 

that code, change scenes, not change position. appreciate :)

on changeposition() method passing hardcoded values player position , assume (12,12,0) on scene space.

you need define spawn manager dynamically witch spawn point in scene want use.

edited:

1: try create singleton gamemanager ( can find singleton pattern examples here ) (important: add dontdestroyonload on gamemanager awake).

2: in gamemanager define vector3 nextposition property or this.

3: declare public vector3 destination on "teleport" script set per teleport on inspector/editor.

4: before line levelmanager.loadlevel (scenename) of code set gamemanager.nextposition = this.destination;

5: if not persisting character between scenes call on 1 of hes behaviours awake() or, if persists create method void onlevelwasloaded(int level) , chage players position setting gamemanager.nextposition ( wisely testing if valid current level before ;) ).

i cant try or better coding because don't have access unity editor hope helps @ last start research solve problem =/.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -