编辑:标记为已解决,除了我什么都没错,问题是错字
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityStandardAssets.Characters.FirstPerson;
public class PlayerVitals : MonoBehaviour
{
private float vital = 0;
public Slider healthSlider;
public int maxHealth;
public int healthFallRate;
public Slider thirstSlider;
public int maxThirst;
public int thirstFallRate;
public Slider staminaSlider;
public int maxStamina;
private int staminaFallRate;
public int staminaFallMult;
private int staminaRegainRate;
public int staminaRegainMult;
private CharacterController charController;
private FirstPersonController playerController;
public DeathMenu deathMenu;
public GameObject FPSController;
public Camera Meep;
void Sart()
{
//sets max value of slider to whatever we set as the max health, thirst etc
healthSlider.maxValue = maxHealth;
healthSlider.value = maxHealth;
thirstSlider.maxValue = maxThirst;
thirstSlider.value = maxThirst;
staminaSlider.maxValue = maxStamina;
staminaSlider.value = maxStamina;
staminaFallRate = 1;
staminaRegainRate = 1;
// call them here in the script so we dont need to write it out everytime
charController = GetComponent<CharacterController>();
playerController = GetComponent<FirstPersonController>();
Meep.enabled = false;
}
void Update()
{
//health fall
if (thirstSlider.value <= 0)
{
healthSlider.value -= Time.deltaTime / healthFallRate * 2;
}
if (healthSlider.value <=0)
{
CharacterDeath();
}
//Thirst
if (thirstSlider.value >= 0)
{
thirstSlider.value -= Time.deltaTime / thirstFallRate;
}
else if (thirstSlider.value <= 0)
{
thirstSlider.value = 0;
}
else if (thirstSlider.value >= maxThirst)
{
thirstSlider.value = maxThirst;
}
//stamina
if(charController.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
{
staminaSlider.value -= Time.deltaTime / staminaFallRate * staminaFallMult;
}
else
{
staminaSlider.value += Time.deltaTime / staminaRegainRate * staminaRegainMult;
}
if (staminaSlider.value >= maxStamina)
{
staminaSlider.value = maxStamina;
}
else if (staminaSlider.value <= 0) { //if the stamina ever reaches zero, we want the run speed to equal the walk speed
staminaSlider.value = 0;
playerController.m_RunSpeed = playerController.m_WalkSpeed;
}
//currently can only walk, even after regen, below fixes that, ever above zero, we want it to be our new normal runspeed
else if (staminaSlider.value >= 0)
{
playerController.m_RunSpeed = playerController.m_RunSpeedNorm;
}
}
void CharacterDeath()
{
// DIE DIE DIE - Reaper main 2028
deathMenu.ToggleEndMenu (vital);
FPSController.SetActive(false);
Meep.enabled = true;
Cursor.lockState = CursorLockMode.None;
}
}
答案 0 :(得分:0)
您键入的是void Sart()
而不是Start()