So I am making a multiplayer typing game. I have a script running in an empty object which generates the word to be typed.
void Start()
{
words[0] = "moose";
words[1] = "cow";
words[2] = "pig";
words[3] = "shark";
words[4] = "dog";
number = Random.Range(0, 5);
typing.text = words[number];
answer = words[number];
input.Select();
}
void Update()
{
if (input.text == answer)
{
input.text = "";
number = Random.Range(0, 4);
typing.text = words[number];
answer = words[number];
input.Select();
}
}
Then I have a script running in the car which tells it to accelerate when you type a word correctly
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections;
public class CarBehaviour : NetworkBehaviour {
private float speed;
public bool accelerate = false;
private float zaxis = 1;
private float xaxis = 0;
public Text typing;
public InputField input;
void Update()
{
if (accelerate == true)
{
speed = 4;
accelerate = false;
}
else
{
speed = 1;
}
Vector3 movement = new Vector3(xaxis, 0.00f, zaxis);
transform.Translate(movement * speed);
}
void LateUpdate()
{
if (input.text == answer)
{
accelerate = true;
}
}
}
But for some reason whenever I type the word correctly the car won’t accelerate. Any help is appreciated
Thanks.