You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}