【发布时间】:2021-04-28 08:13:24
【问题描述】:
当我触摸“死亡”层时,我正在尝试重置我的玩家的位置(到 0、2、0)。我该怎么做?
我尝试使用名为isDead 的bool,我的代码如下所示:
if(isDead)
{
transform.position = new Vector3(0f, 2f,0f);
}
这是我的全部代码,可能会有所帮助
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementScript : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
scripts
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
public float jumpHeight = 3f;
Vector3 velocity;
bool isGrounded;
bool isDead;
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
for evig når den treffer bakken
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
controller.Move(velocity * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
}
}
我不知道该怎么做。有什么建议?谢谢!
【问题讨论】:
标签: c# visual-studio unity3d