我看了一些關于如何從腳本發送布林值的教程,所以腳本是我寫的代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sender : MonoBehaviour
{
public bool ktp;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
bool ktp = true;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
和
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class empf?nger : MonoBehaviour
{
public sender script;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (script.ktp == true)
{
Debug.Log(script.ktp);
}
}
}
我正在測驗將布林值從一個腳本發送到另一個腳本,在這里我只是試圖將另一個腳本宣告的布林值輸出到控制臺。
我期待它的作業。
uj5u.com熱心網友回復:
您實際上是在“創建”變數兩次。在中,當您在函式中分配變數時sender
,從中洗掉。bool
sender.cs
using System.Collections.Generic;
using UnityEngine;
public class sender : MonoBehaviour
{
public bool ktp;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ktp = true;
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536463.html