I’ve created a Gui Texture (button) that will allow the object to enter a door (by touching it on the android device and spawn at another door, the thing is i want that gui texture (button) to stay on the door and not follow the CAMERA around is that possible?
Thanks!
using UnityEngine;
using System.Collections;
public class Teleport : MonoBehaviour {
public Transform Characters;
Animator anim;
public Transform GroundCheck;
public Transform playerCheck;
float playerRadius = 0.5f;
public LayerMask whatIsPlayer;
public Transform Teleport2;
bool Teleported1 = false;
public GUITexture guiEnterDoor;
private bool EnterDoor = false;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
IEnumerator Wait() {
Debug.Log("Before Waiting 1 seconds");
yield return new WaitForSeconds (1);
Characters.transform.position = Teleport2.transform.position;
anim.SetBool ("EnteringDoor", false);
Debug.Log("After Waiting 1 Seconds");
}
void Update() {
if (Input.touchCount > 0) {
// Get the touch info
Touch t = Input.GetTouch (0);
// Did the touch action just begin?
if (t.phase == TouchPhase.Began) {
// Are we touching the Door?
if (guiEnterDoor.HitTest (t.position, Camera.main)) {
Debug.Log ("Touching EnterDoor");
EnterDoor = true;
}
}
// Did the touch end?
if (t.phase == TouchPhase.Ended)
{
// Stop all movement
EnterDoor = false;
rigidbody2D.velocity = Vector2.zero;
}
}
}
// Update is called once per frame
void FixedUpdate () {
Teleported1 = Physics2D.OverlapCircle (GroundCheck.position, playerRadius, whatIsPlayer);
anim.SetBool ("DOOR1", Teleported1);
if (EnterDoor)
{
if (Teleported1) {
StartCoroutine(Wait ());
}
}
}
}