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 SurfaceDetection : MonoBehaviour
- {
- public bool IsSurface;
- Vector3 initialPos;
- private void Start()
- {
- initialPos = transform.localPosition;
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.K))
- {
- if (IsSurface)
- {
- transform.localPosition += new Vector3(10f, 0f, 0f);
- CheckGround();
- }
- else
- {
- Debug.Log("is surface false");
- transform.localPosition = new Vector3(initialPos.x, 0f, 0f);
- transform.localPosition += new Vector3(0f, 0f, 5f);
- IsSurface = true;
- }
- }
- }
- void CheckGround()
- {
- Debug.Log("check ground");
- RaycastHit Hit;
- if (Physics.Raycast(transform.localPosition, Vector3.down, out Hit, Mathf.Infinity))
- {
- IsSurface = true;
- Debug.Log(Hit.collider.name);
- }
- else
- {
- IsSurface = false;
- transform.localPosition -= new Vector3(10f, 0f, 0f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement