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 Player : MonoBehaviour {
- public GameObject Spot;
- public float Speed=10.0f;
- public float rotation = 200.0f;
- public float PlayerHeight = 2;
- // Update is called once per frame
- void Update () {
- var x = Input.GetAxis("Horizontal") * Time.deltaTime * rotation;
- var z = Input.GetAxis("Vertical") * Time.deltaTime * Speed;
- transform.Rotate(0, x, 0);
- transform.Translate(0, 0, z);
- if (Input.GetKeyDown(KeyCode.Mouse0))
- {
- getTerrainPos();
- }
- }
- void LateUpdate()
- {
- Vector3 pos = transform.position;
- pos.y = Terrain.activeTerrain.SampleHeight(transform.position)+ PlayerHeight;
- transform.position = pos;
- }
- private void getTerrainPos()
- {
- Vector3 infront;
- infront = transform.position + transform.forward;
- infront.y = Terrain.activeTerrain.SampleHeight(infront) + 0.1f;
- if (Mathf.FloorToInt(infront.x) == Mathf.RoundToInt(infront.x))//if = then round down else round up
- infront.x = Mathf.FloorToInt(infront.x);
- else
- infront.x = Mathf.CeilToInt(infront.x);
- if (Mathf.FloorToInt(infront.z) == Mathf.RoundToInt(infront.z))//if = then round down else round up
- infront.z = Mathf.FloorToInt(infront.z);
- else
- infront.z = Mathf.CeilToInt(infront.z);
- Instantiate(Spot,infront,Quaternion.identity);
- Debug.Log(infront);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement