|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
using UnityEngine.AI;
|
|
|
|
|
|
public class move : MonoBehaviour
|
|
|
{
|
|
|
public GameObject s;
|
|
|
public jump j;
|
|
|
// Start is called before the first frame update
|
|
|
void Start()
|
|
|
{
|
|
|
// s = GameObject.Find("Sphere"); // 从层级面板中搜索名字为Sphere的游戏对象
|
|
|
|
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
|
void Update()
|
|
|
{
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.W)) {
|
|
|
float z = this.transform.position.z; // 定义Z接受当前的Z坐标
|
|
|
|
|
|
z++;
|
|
|
|
|
|
this.transform.position = new Vector3(
|
|
|
this.transform.position.x,
|
|
|
this.transform.position.y,
|
|
|
z);
|
|
|
|
|
|
|
|
|
s.GetComponent<jump>().time-=1;
|
|
|
}
|
|
|
|
|
|
if (Input.GetKeyUp(KeyCode.S))
|
|
|
{
|
|
|
float z = this.transform.position.z; // 定义Z接受当前的Z坐标
|
|
|
|
|
|
z -= .1f;
|
|
|
|
|
|
this.transform.position = new Vector3(
|
|
|
this.transform.position.x,
|
|
|
this.transform.position.y,
|
|
|
z);
|
|
|
|
|
|
j.add();
|
|
|
}
|
|
|
|
|
|
// moveUp();
|
|
|
}
|
|
|
|
|
|
void moveUp() {
|
|
|
float x = this.transform.position.x;
|
|
|
float y = this.transform.position.y;
|
|
|
float z = this.transform.position.z;
|
|
|
|
|
|
if (Input.GetButton("Horizontal"))
|
|
|
{
|
|
|
float h = Input.GetAxis("Horizontal");
|
|
|
|
|
|
x += h * 0.1f; // 当我们H为负数的时候,则向左移;
|
|
|
|
|
|
this.transform.position = new Vector3(
|
|
|
x,
|
|
|
y,
|
|
|
z);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Input.GetButton("Vertical"))
|
|
|
{
|
|
|
float v = Input.GetAxis("Vertical");
|
|
|
|
|
|
z += v * 0.1f;
|
|
|
|
|
|
this.transform.position = new Vector3(
|
|
|
x,
|
|
|
y,
|
|
|
z);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|