Why is this always true?
public float speed;
bool working = false;
// Start is called before the first frame update
void Start()
{
skilling = false;
speed = 3f;
}
// Update is called once per frame
void Update()
{
Vector3 playerInput = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
transform.position = transform.position + playerInput.normalized * speed * Time.deltaTime;
if(speed >= 500f)
{
print("test");
}
}
originally i wanted to make the condition based on the "working" boolean, aswell as Key Input. It was always true.
I am losing my mind..
test
test
test
test
test
test
I tried the If-Statement with the Float as in the example, with a bool and also with a collision. It was always true. I must have messed up somewhere, but i cannot find it.
Edit:
Complete Code:
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
float speed;
bool working = false;
// Start is called before the first frame update
void Start()
{
speed = 3f;
}
// Update is called once per frame
void Update()
{
Vector3 playerInput = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
transform.position = transform.position + playerInput.normalized * speed * Time.deltaTime;
if(speed >= 500f)
{
print("test");
}
}
/*void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Skill")
{
//skilling = true;
}
else skilling = false;
}*/
}
`
I removed the public from the speed variable, still true.
>Solution :
Possible solutions:
1- Make sure you did not modify the speed variable from the inspector since it’s public.
2- Make sure other classes are not changing the speed variable at the start.