Hello,
i’m trying to attach a script to a Slider for Stamina on my FPS player, and i’m trying to access the FPS script provided by Unity Standard Assets.
Here is the code: I’m getting 6 errors and even if i pass over it over and over, i can’t find any error. Any help please… Would be greatly appreciated.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;
public class Stamina : MonoBehaviour {
public Slider sliderStamina;
public int maxStamina;
private int perteStamina;
public int perteStaminaMult;
private int gainStamina;
public int gainStaminaMult;
private CharacterController charController;
private FirstPersonController playerController;
void Start () {
sliderStamina.maxValue = maxStamina;
sliderStamina.value = maxStamina;
perteStamina = 1;
gainStamina = 1;
charController = GetComponent <CharacterController> ();
playerController = GetComponent <FirstPersonController> ();
}
void Update () {
if (charController.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
{
sliderStamina.value -= Time.deltaTime / perteStamina * perteStaminaMult;
}
else
{
sliderStamina.value += Time.deltaTime / gainStamina * gainStaminaMult;
}
if (sliderStamina.value >= maxStamina)
{
sliderStamina.value = maxStamina;
}
else if (sliderStamina.value <=0)
{
sliderStamina.value=0;
playerController.m_RunSpeed = playerController.m_WalkSpeed;
}
else if (sliderStamina.value >=0)
{
playerController.m_RunSpeed = playerController.m_RunSpeedNorm;
}
}
}
Here are my errors in console.
Assets/Stamina.cs(30,55): error CS1525: Unexpected symbol <internal>' Assets/Stamina.cs(34,20): error CS1519: Unexpected symbol else’ in class, struct, or interface member dec
Assets/Stamina.cs(36,46): error CS1519: Unexpected symbol +=' in class, struct, or interface member decla Assets/Stamina.cs(36,63): error CS1519: Unexpected symbol /’ in class, struct, or interface member declarl
Assets/Stamina.cs(36,79): error CS0102: The type Stamina' already contains a definition for gainStaminaMult’
Assets/Stamina.cs(38,18): error CS8025: Parsing error
I’m banging my head and can’t find anything ![]()