Question by
gamingkid · Aug 03, 2016 at 08:07 PM ·
transformarraypositionrandom.range
How can i use transform.position to a gameobject in an array?
using UnityEngine; using System.Collections;
public class Teleport : MonoBehaviour { public GameObject[] otherPortal; void Start () { otherPortal = GameObject.FindGameObjectsWithTag ("portal"); }
void Update () {
} void OnTriggerEnter2D(Collider2D other) { Debug.Log ("Hit the portal"); if (other.tag == "Player") { other.transform.position = otherPortal.transform.position; } } }
Comment
Answer by XBabineOne · Aug 05, 2016 at 02:36 PM
Hey,
If you remember well, Array have index. so, for exemple myArray[1].
I think you just forget to put the index for the portal. Normely it will be this:
other.transform.position = otherPortal[1].transform.position;
Try this and tell me if it's works ! :)