I have 2 files/scripts of code:
the first one:
using System.Collections.Generic;
using UnityEngine;
public class MoveLeft : MonoBehaviour
{
private float Speed = 15f;
private PlayerController playerControllerScript;
// Start is called before the first frame update
void Start()
{
playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
}
// Update is called once per frame
void Update()
{
if(playerControllerScript.gameOver == false)
{
transform.Translate(Vector3.left * Time.deltaTime * Speed);
}
//transform.Translate(Vector3.left * Time.deltaTime * Speed);
}
}
the second one:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRB;
public float JumpForce = 150;
public float GravityModifier;
public bool OnTheGround = true;
public bool gameOver;
// Start is called before the first frame update
void Start()
{
playerRB = GetComponent<Rigidbody>();
Physics.gravity *= GravityModifier;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)&& OnTheGround)
{
playerRB.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
OnTheGround = false;
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
OnTheGround = true;
}
if (collision.gameObject.CompareTag("Obsticle"))
{
Debug.Log("Game over");
gameOver = true;
}
}
}
So for my simple game, I need to check if the game over 'bool' is checked or not(true or false) then send the bool value to the first script. I have already tried this but I am repeatedly getting an error.
Please help me. I am not very good at programming.