- Home /
Question by
Chefix · Mar 16, 2017 at 09:12 AM ·
2dscripting problem2d gameportals
2D Linked Portals
Hello, I'm working on a 2D game and I added linked portals to it. For instance if I stand on top of portal A and press the teleport button, I get teleported to portal B. And if I stand on top of portal B and press the teleport button, I get teleported to portal A.
The problem is that one of the portals works and the other doesn't for some reason...
The script attached to both of them is the following:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class telep : MonoBehaviour {
private GameObject player;
public GameObject Destination;
// Use this for initialization
void Start () {
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update () {
if ((player.transform.position.x > (transform.position.x - 0.5)) && (player.transform.position.x < (transform.position.x + 0.5)))
if (Input.GetButton("Teleport"))
{
player.transform.position = new Vector3(Destination.transform.position.x, Destination.transform.position.y, 0);
}
}
}
Here is a video to better understand the problem: https://www.youtube.com/watch?v=XwFmILYMCWE
Comment
Are you sure you have dragged & dropped the correct gameobject when you select the top right portal ?
Absolutely, I dragged the left one into the right one's component and vice versa. Seriously I have no idea what to do at this point...