How teleport gameobject to specific location in c#?
Hi, i teleport object with 2 scripts in JS
1 script , This script is added to a collider
function OnTriggerEnter(hit:Collider) {
if(hit.gameObject.name == "idolom")
{
gameObject.Find("idmon").SendMessage("React");
}
}
2 script add to player
function React () { transform.position = Vector3(180, 1.38, 175); }
but i don't know convert to c#
I have seen many scripts to teleport an object to another object, but I have not seen one that teleport an object to specific coordinates that is what interests me.
Thanks
Regards!!
Answer by BabilinApps · Oct 03, 2015 at 10:29 PM
have to:
Change the word function to void (All functions in C# are called voids)
add the word "new" to Vector3. (C# requires the use of the word new unless you are deriving from Vector3 like Vector3.Distance
Add an "f" to any value that has a decimal or is not an integer (this makes sure that the number is a float and not a double)
void React () { transform.position = new Vector3(180, 1.38f, 175); }
Answer by Vylax · Mar 20, 2016 at 09:04 PM
Script 1 :
void OnTriggerEnter(Collider hit) {
if(hit.gameObject.name == "idolom")
{
GameObject.Find("idmon").SendMessage("React");
}
script 2 :
void React () {
transform.position = new Vector3(180, 1.38f, 175);
}
and it would work...
you can also use this tool but it's in developpement...
Answer by sebas321123 · Mar 20, 2016 at 08:19 PM
public Transform trasporte;
OnTriggerEnter2D(Collider2D collider ){
collider.gameObject.transform.position = trasporte.position; } so?
he's game isn't in 2D because for the teleport he use a Vector 3 position so you're code won't work
Your answer
![](https://koobas.hobune.stream/wayback/20220612035929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object deletes when a script is added. 1 Answer
How do you get that Grow Home look 1 Answer
How to rotate object back and forth from one rotation to another? 2 Answers
check object destroyed and load new scene 0 Answers
Object Reference Error 1 Answer