Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class charTeleport2 : MonoBehaviour {
  5. //Animator anim = new Animator();
  6. public GameObject spawnLeft = new GameObject();
  7. public GameObject spawnCentre = new GameObject();
  8. public GameObject spawnRight = new GameObject();
  9. public static float speed=5f;
  10. public GameObject prefab;
  11. int counter=0;
  12. void Start () {
  13. Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18. counter += 1;
  19. if(counter==10){
  20. counter=0;
  21. if(Input.GetKeyDown(KeyCode.D))
  22. {
  23.  
  24. if(prefab.transform.position.x==spawnLeft.transform.position.x)
  25. {Destroy(prefab);
  26. Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
  27. }
  28. if(prefab.transform.position.x==spawnCentre.transform.position.x)
  29. {Destroy(prefab);
  30. Instantiate(prefab,new Vector3(spawnRight.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
  31. }
  32. }
  33. if (Input.GetKeyDown(KeyCode.A))
  34. {
  35. if(prefab.transform.position.x==spawnRight.transform.position.x)
  36. {Destroy(prefab);
  37. Instantiate(prefab,new Vector3(spawnCentre.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
  38. }
  39. if(prefab.transform.position.x==spawnCentre.transform.position.x)
  40. {Destroy(prefab);
  41. Instantiate(prefab,new Vector3(spawnLeft.transform.position.x,prefab.transform.position.y,prefab.transform.position.z),Quaternion.identity);
  42. }
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement