Hi everyone,
I have just started with Unity in the last week, trying to teach myself using the Learn section from this website as well as these forums and Youtube tutorials.
The problem which I have run into is I have decided to expand upon the “Roll-a-Ball” tutorial game and want to create a “speed boost” when the player moves over a 3D plane. I have spent the last 3 days searching online and tried all the ideas which others have suggested relating to similar problems, nothing has worked. I will post the relevant code below along with my idea as to how to achieve this boost.
public class PlayerController : MonoBehaviour {
private float speed;
void Start (){
speed = 10;
}
void FixedUpdate (){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce (movement * speed);
}
void OnCollisionStay(){
if (gameObject.CompareTag ("Speed Boost")) {
speed = speed * 2;
}
}
}
I realise that the solution to my problem is probably something extremely obvious but I feel like I have tried everything and nothing has worked. Any help as to why it is not working would be greatly appreciated, even if you simply say that I am completely off in my thinking.