I am trying to write a C# script in Unity that would move other objects in the game. I tried this code below, but it didn't work. The errors are saying that REDpos, RRDpos, RADpos, and RCDpos, do not exist in the current context. Please help me figure out how to fix this! I am abeginner, so sorry if it's really obvious.
Here is my code:
using UnityEngine;
using System.Collections;
public class TeamSelect : MonoBehaviour {
public GameObject RCD;
public GameObject RAD;
public GameObject RED;
public GameObject RRD;
// Use this for initialization
void Start () {
RCD = GameObject.Find("RCD");
RAD = GameObject.Find("RAD");
RED = GameObject.Find("RED");
RRD = GameObject.Find("RRD");
}
// Update is called once per frame
void Update () {
RCDpos = RCD.transform.position.x;
RADpos = RAD.transform.position.x;
REDpos = RED.transform.position.x;
RRDpos = RRD.transform.position.x;
if (Input.GetKey("right")) {
RCDpos = RCDpos - 0.1;
RADpos = RADpos - 0.1;
REDpos = REDpos - 0.1;
RRDpos = RRDpos - 0.1;
}
if (Input.GetKey("left")) {
RCDpos = RCDpos + 0.1;
RADpos = RADpos + 0.1;
REDpos = REDpos + 0.1;
RRDpos = RRDpos + 0.1;
}
}
}