What i am trying to do: there are 2 block 1 will rotate a little only when i press the right arrow button the other will rotate only when i press left there are 2 script learning1 is in “cube” gameobject learning2 is in cube2.
Purpose of the code: learning2 will have 2 rotation method SpinLeft() and SpinRight() learning1 will have 2 if statement one will connect see if the left arrow is pressed then cube will rotate the other will check if right arrow is pressed then cube2 rotates but i am sure you can figure it out just by reading the code. Sorry for a lengthy explanation. The error i get is in the title.
Learning2:
using UnityEngine;
using System.Collections;
public class Learning2 : MonoBehaviour {
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SpinLeft()
{
transform.Rotate (0,0,60 * Time.deltaTime);
}
public void SpinRight()
{
transform.Rotate (0, 0, -60 * Time.deltaTime);
}
}
Learning1:
using UnityEngine;
using System.Collections;
public class Learning : MonoBehaviour {
GameObject Cube;
Learning2 learning2;
void Start () {
Cube=GameObject.Find("Cube");
learning2 = GameObject.Find ("Cube2").GetComponent<Learning2>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
Cube.GetComponent<Learning2>().SpinLeft();
}
if(Input.GetKeyDown(KeyCode.RightArrow))
{
learning2.SpinRight();
}
}
}