|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Character: MonoBehaviour
|
|
{
|
|
bool move = true;
|
|
bool floorFound = false;
|
|
Vector3 halfJump = new Vector3 (1.0f, 0.5f, 1.0f);
|
|
|
|
void Update ()
|
|
{
|
|
if (Input.GetKeyDown (KeyCode.LeftArrow)) {
|
|
transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - 90, transform.rotation.eulerAngles.z);
|
|
}
|
|
if (Input.GetKeyDown (KeyCode.RightArrow)) {
|
|
transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + 90, transform.rotation.eulerAngles.z);
|
|
}
|
|
if (Input.GetKeyDown (KeyCode.UpArrow)) {
|
|
OverlapBoxExample childScript = this.transform.GetChild (2).GetComponent < OverlapBoxExample > ();
|
|
if(transform.position.y < 1.5){
|
|
foreach (Collider x in childScript.hitColliders) {
|
|
if (x.name == "Wall" || x.name == "Stump" || x.name == "Water") {
|
|
move = false;
|
|
break;
|
|
}
|
|
}
|
|
if (move == true ) {
|
|
transform.position -= transform.forward;
|
|
}
|
|
}else{
|
|
transform.position -= transform.forward;
|
|
transform.position -= Vector3.Scale(halfJump , transform.up);
|
|
}
|
|
}
|
|
if (Input.GetKeyUp (KeyCode.UpArrow)) {
|
|
move = true;
|
|
}
|
|
if (Input.GetKeyDown (KeyCode.Space)) {
|
|
OverlapBoxExample childScript = this.transform.GetChild (2).GetComponent < OverlapBoxExample > ();
|
|
foreach (Collider x in childScript.hitColliders) {
|
|
//Debug.Log(x.name);
|
|
if (x.name == "Stump" && transform.position.y < 1.5) {
|
|
transform.position -= transform.forward;
|
|
transform.position += Vector3.Scale(halfJump , transform.up);
|
|
break;
|
|
} else if (x.name == "Water") {
|
|
transform.position -= transform.forward;
|
|
transform.position += Vector3.Scale(halfJump , transform.up);
|
|
transform.position -= transform.forward;
|
|
transform.position -= Vector3.Scale(halfJump , transform.up);
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|