Поэтому я хочу, чтобы кнопка меняла переменную в одном скрипте. Затем я хочу другой скрипт, чтобы получить эту переменную из первого скрипта. Как мне это сделать.
Я пробовал кое-что, но я не уверен, правильно ли я их сделал
Когда я пытаюсь сделать это, как в коде ниже. Затем он выдает мне сообщение:
'Не удалось найти тип или имя пространства имен' jumpscript '(отсутствует директива using или ссылка на сборку?)'
Jump.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour
{
public bool jump = false;
// Start is called before the first frame update
public void JumpOnClick()
{
jump = true;
}
// Update is called once per frame
void Update()
{
}
}
PlayerMovement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public Joystick joystick;
public jumpscript Jump;
public float runSpeed = 40f;
float horizontalMove = 0f;
// Update is called once per frame
void Update()
{
if (joystick.Horizontal >= .2f)
{
horizontalMove = runSpeed;
} else if (joystick.Horizontal <= -.2f)
{
horizontalMove = -runSpeed;
} else
{
horizontalMove = 0f;
}
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, Jump.jump);
Jump.jump = false;
}
}
EDIT: Я заставляю персонажа прыгать, но персонаж всегда прыгает.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public Joystick joystick;
public Jump jumpScript;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool Jump = false;
// Update is called once per frame
void Update()
{
if (jumpScript.jump == true)
{
Jump = true;
}
if (joystick.Horizontal >= .2f)
{
horizontalMove = runSpeed;
} else if (joystick.Horizontal <= -.2f)
{
horizontalMove = -runSpeed;
} else
{
horizontalMove = 0f;
}
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, Jump);
Jump = false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour
{
public bool jump = false;
// Start is called before the first frame update
public void JumpOnClick()
{
jump = true;
jump = false;
}
// Update is called once per frame
void Update()
{
}
}
Пожалуйста, помогите мне.