The code is working fine, but you just cant see the difference, because the movement speed is way too slow. Also the rotating function is not even rotating…
I fixed some bugs and improved your code:
//Variables
public GameObject Aircraft;
private bool canMoveaircraft;
private float Timer;
public void Pushback()
{
//Start rotating aircraft
InvokeRepeating("Rotate", 0f, 0.01f);
}
void Update()
{
Debug.Log(Aircraft.transform.rotation.z);
//Increase timer
Timer += Time.deltaTime;
//If the aircraft is turned then:
if (Aircraft.transform.rotation.z <= -0.8f)
{
//Stop rotating aircraft
CancelInvoke("Rotate");
canMoveaircraft = true;
}
//If boolean canMoveaircraft is enabled:
if (canMoveaircraft)
{
//Set timer to 0
Timer = 0;
//If timer is smaller than 5:
if (Timer < 1f)
{
//Move aircraft
Aircraft.transform.Translate(new Vector3(0, 0.1f, 0));
}
}
}
void Rotate()
{
//Rotate aircraft
Aircraft.transform.Rotate(Vector3.forward, Time.deltaTime * 20f, Space.Self);
}
As we don’t see the other script, we cant be sure that its typed correct. What I try if something is not working is to go back to the most simplest form you can think of to make this work. I would try something like this:
public class ButtonToClick : MonoBehaviour{
void OnGUI()
{
if(GUI.Button(new Rect(10,10,100,100), "Click this"))){
GameObject.Find("PushBackButton").GetComponent<PushBackButton>().PushBack();
}
}
}
public class PushBackButton : Monobehaviour{
public void PushBack(){
Debug.Log("PushBack!");
}
}
When you are absolutely sure that the communication between scripts is correct, continue adding code.
Seems right. Make sure you GameObject the behavior is attached to is ACTIVE in the inspector when you press play. If you are pulling this from a prefab, you might have issues considering it might not be in the scene.