Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class keyboard : MonoBehaviour {
- [SerializeField] Transform player;
- [SerializeField] Camera cam;
- [SerializeField] Collider textCollider;
- bool move = false;
- int boost = 10;
- // Use this for initialization
- void Start () {
- }
- int hitCount = 0;
- void Update () {
- if (!move)
- {
- RaycastHit hit;
- if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit)) {
- if (hit.transform.ToString().Equals("Plane (UnityEngine.Transform)"))
- {
- hitCount++;
- }
- else {
- hitCount = 0;
- }
- if (hitCount > 60) {
- move = true;
- }
- }
- }
- else
- {
- 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);
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.name.Equals("GoHome")) {
- Debug.Log("gohome");
- move = false;
- player.position = new Vector3(player.position.x, 2.5f, player.position.z - 83.31f);
- move = true;
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- player.position = new Vector3(player.position.x, 2.5f, -40);
- move = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement