Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class charTeleport2 : MonoBehaviour {
- //Animator anim = new Animator();
- public GameObject spawnLeft = new GameObject();
- public GameObject spawnCentre = new GameObject();
- public GameObject spawnRight = new GameObject();
- public static float speed=5f;
- public GameObject prefab;
- int counter=0;
- void Start () {
- Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
- }
- // Update is called once per frame
- void Update () {
- counter += 1;
- if(counter==10){
- counter=0;
- if(Input.GetKeyDown(KeyCode.D))
- {
- if(prefab.transform.position.x==spawnLeft.transform.position.x)
- {Destroy(prefab);
- Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
- }
- if(prefab.transform.position.x==spawnCentre.transform.position.x)
- {Destroy(prefab);
- Instantiate(prefab,new Vector3(spawnRight.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
- }
- }
- if (Input.GetKeyDown(KeyCode.A))
- {
- if(prefab.transform.position.x==spawnRight.transform.position.x)
- {Destroy(prefab);
- Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
- }
- if(prefab.transform.position.x==spawnCentre.transform.position.x)
- {Destroy(prefab);
- Instantiate(prefab,new Vector3(spawnLeft.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement