I’m making a simple racing game and part of the game is running into certain objects that will increase your speed, but I can’t get the speed to change. Here’s what I have for code:
using UnityEngine;
using System.Collections;
public class P1Move : MonoBehaviour {
public float speed;
public float increaseSpeed;
private Rigidbody rb;
private Vector3 movement;
private float actualInc;
private bool spdUp = false;
void Start()
{
rb = GetComponent<Rigidbody>();
actualInc = speed * increaseSpeed;
}
void FixedUpdate()
{
if (spdUp == false)
{
float h = Input.GetAxisRaw("HorizontalP1");
float v = Input.GetAxisRaw("VerticalP1");
Vector3 movement = new Vector3(h, 0, v);
rb.AddForce(movement * speed);
}
if (spdUp == true)
{
float h = Input.GetAxisRaw("HorizontalP1");
float v = Input.GetAxisRaw("VerticalP1");
Vector3 movement = new Vector3(h, 0, v);
rb.AddForce(movement * actualInc);
}
}
void onTriggerEnter (Collider other)
{
if (other.tag == "SpdUp")
{
spdUp = true;
}
}
}