Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what i mean by this, is that im trying to make a script for a survival game, when the player runs he heats up. ive got the UI all set up its just the script that needs work.

it keeps saying: "(19,27) Math does not exist in current context"
and
"(29,27) Math does not exist in current context"

what should i do to make it work?

heres the script:
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Temperature : MonoBehaviour
{
    public float minTemperature = 32;
    public float temperature = 32;
    public float maxTemperature = 105;
    
    public float temperatureFactor = 30;
    public bool overheating;
    void Update()
    {
        float tempChange = Time.deltaTime * temperatureFactor;
        if (Input.GetKey(KeyCode.LeftShift) && !overheating)
        {
            temperature = Math.Min(maxTemperature, temperature + tempChange);
            if (temperature == maxTemperature)
            {
                overheating = true;
            }
        }
        else if (!Input.GetKey(KeyCode.W))
        {
            temperature = Math.Max(minTemperature, temperature - tempChange);
            if (temperature == minTemperature)
            {
                overheating = false;
            }
        }
    }
}


What I have tried:

ive surfed the internet for answers but i couldn,t find anything
Posted
Updated 5-Mar-21 18:16pm
v2
Comments
PIEBALDconsult 5-Mar-21 19:45pm    
System.Math?
BillWoodruff 6-Mar-21 4:14am    
We can't read your mind: show the code that creates the Class, and the code where the error occurs.

1 solution

You don't have using System; at the top of the code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900