I am making a Game and i dont know how to Code in a teleporter that has a 7 digit Adress that when used will allow a player/ object through and arrive at a 2nd teleporter, but i want it to work ifit was a network of them all, can you help me and also say what scripting language i should use, thanks ![]()
Do you have any parts of this script created?
Are all your teleport positions on the same scene or to different scenes?
If you don’t know basic scripting it would serve you better to learn to create your script, then post it here for help with the errors. If your wanting someone to create a script for you for money or trade, the collaboration section of the forum is the place to be.
If I were writing this, I’d do it 1 of 2 ways:
Create a document in Assets/Resources that listed the valid combinations and the name of the Scene and the name of the teleporter in the scene that the destination goes to. Then I’d have a teleportation manager script that handled teleportation. Then I’d have a teleporter script for the teleporter that interacted with the manager.
Or…
Have a way of encoding the name of the map and the name of the teleporter into 7 digits. Then write a script that decodes that info and handles the teleportation accordingly.
Thinking about it, the second way is more my style, where the first is probably simpler.
I Like your style.
The matching of the digits to what scene is the easy part, using just conditions.
if(varThatHoldsDigits==1234567) {
Application.LoadLevel("NextLevelName");
}
If a new player was being spawned at the new scene, the player could just swawn at the teleport pad. If the player is not being spawned at each new scene using DontDestroy, or the new scene has more than one teleport pad, than the player would need a system to transport the player to the correct poition on that new scene.
The same teleport script that loaded a new scene or sends the player to a new position could (eg) use playerPrefs, so that the prefs are set to the new position on the new scene or a new position on the same scene.
Actually, I was thinking more like:
1234567 - Section 12, map 34 (scene file Level-12-34.unity), teleporter 567 (object name “Teleporter 567”).
Then the logic works for everything and you don’t have to hard-code all the locations. You’d have to know which are valid and which aren’t, though… So maybe that wouldn’t work well… Unless invalid teleporter numbers dumped you into a main depot or something.
You’d have to be careful naming things, too.
Actually, the more I think about it, the less I like my second way. It’s too fragile. Having a central list is better.
Here is a small working script of the method I described above.
Place this script on the player so it goes with it from scene to scene, and assign the player to the playerObject var. Also remember to add your next level to the build and its scene name to the script.
No offence to the OP but I kind of newbied it out so you could see how it works. All you have to do now is add more conditions, or loop through a array of scene names or codes to make this code more advanced. Also to trigger the code just flip the bool in the inspector to check the current code.
var theCode : int;
var sceneNameOne : String;
var newScenePos = Vector3(0,0,0);
var sameScenePos = Vector3(0,0,0);
var checkTheCode : boolean;
var playerObject : GameObject;
function Start() {
//------------//
theCode = 1234567;
Invoke("RePos", 0.0);
//------------//
}
function Update() {
//------------//
if(checkTheCode) {
checkTheCode = false;
//------------//
if(theCode==1234567) {
theCode = 0;
if(playerObject) {
PlayerPrefs.SetFloat("posX", newScenePos.x);
PlayerPrefs.SetFloat("posY", newScenePos.y);
PlayerPrefs.SetFloat("posZ", newScenePos.z);
DontDestroyOnLoad (playerObject);
}
Application.LoadLevel(sceneNameOne);
Invoke("RePos", 0.0);
}
else if(theCode==7654321) {
theCode = 0;
PlayerPrefs.SetFloat("posX", sameScenePos.x);
PlayerPrefs.SetFloat("posY", sameScenePos.y);
PlayerPrefs.SetFloat("posZ", sameScenePos.z);
Invoke("RePos", 0.1);
}
//------------//
}
//------------//
}
function RePos() {
if(playerObject) {
print(name + " : " + PlayerPrefs.GetFloat("posY"));
playerObject.transform.position.x = PlayerPrefs.GetFloat("posX");
playerObject.transform.position.y =PlayerPrefs.GetFloat("posY");
playerObject.transform.position.z =PlayerPrefs.GetFloat("posZ");
}
}