Advertisement
Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class keyboard : MonoBehaviour {
  6.  
  7. [SerializeField] Transform player;
  8. [SerializeField] Camera cam;
  9. [SerializeField] Collider textCollider;
  10.  
  11. bool move = false;
  12. int boost = 10;
  13.  
  14. // Use this for initialization
  15. void Start () {
  16.  
  17. }
  18.  
  19. int hitCount = 0;
  20.  
  21. void Update () {
  22.  
  23. if (!move)
  24. {
  25. RaycastHit hit;
  26. if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit)) {
  27. if (hit.transform.ToString().Equals("Plane (UnityEngine.Transform)"))
  28. {
  29. hitCount++;
  30. }
  31. else {
  32. hitCount = 0;
  33. }
  34. if (hitCount > 60) {
  35. move = true;
  36. }
  37. }
  38. }
  39. else
  40. {
  41. player.position = Vector3.MoveTowards(player.position, new Vector3(player.position.x + 2 * cam.transform.rotation.y, 2.5f, player.position.z + 1), Time.deltaTime * boost);
  42.  
  43. }
  44.  
  45. }
  46.  
  47. private void OnCollisionEnter(Collision collision)
  48. {
  49. if (collision.gameObject.name.Equals("GoHome")) {
  50. Debug.Log("gohome");
  51. move = false;
  52. player.position = new Vector3(player.position.x, 2.5f, player.position.z - 83.31f);
  53. move = true;
  54. }
  55. }
  56.  
  57. private void OnTriggerEnter(Collider other)
  58. {
  59. player.position = new Vector3(player.position.x, 2.5f, -40);
  60. move = false;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement