Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help with getting a bool from one script to another

Discussion in 'Scripting' started by CdPlayer129, Nov 23, 2021.

  1. CdPlayer129

    CdPlayer129

    Joined:
    Nov 13, 2021
    Posts:
    1
    Please Help I've Looked At Lots Of Threads To See How To Do This But I Just Can't Figure It Out. I need to move the bool CanWallRun to Script Two btw I'm Using Unity Version 2020.3.21f1 Lts.

    else if (!isGrounded)

    so I can do

    else if (!isGrounded && !CanWallRun)

    Script One

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class WallRunning: MonoBehaviour
    {
    public bool CanWallRun()

    }

    Script Two


    using UnityEngine;

    public class PlayerMovement: MonoBehaviour
    {
    private void Update()
    {
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);



    MyInput();
    ControlDrag();
    ControlSpeed();

    if (Input.GetKeyDown(jumpKey) && isGrounded)
    {
    Jump();
    }
    else if (!isGrounded)
    {
    gravity();
    }



    slopeMoveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);
    }

    }
     
  2. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    Script two needs reference to script one to find your CanWallRun method.

    Code (CSharp):
    1. bool wallRunning = WallRunningObject.GetComponent<WallRunning>().CanWallRun();