1
我正在製作一個基本的籃球比賽,我有一個公共布爾值,稱爲dunkComplete,在球被扣球后被激活並被附加到球腳本上,我試圖在遊戲中引用該布爾值經理腳本,但由於某種原因,即使dunkComplete成爲真正的遊戲管理器副本不會,但請參閱遊戲管理器腳本。引用非靜態變量
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class game_manager : MonoBehaviour {
public GameObject Basket;
private float x_value;
private float y_value;
public GameObject ball;
private ball_script basketBallScript;
private bool dunkCompleteOperation;
// Use this for initialization
void Start() {
basketBallScript = ball.GetComponent<ball_script>();
Vector2 randomVector = new Vector2(Random.Range(-9f, 9f), Random.Range(0f, 3f));
Debug.Log(randomVector);
Instantiate(Basket, randomVector, transform.rotation);
Instantiate(ball, new Vector2(0, -3.5f), transform.rotation);
}
// Update is called once per frame
void Update() {
dunkCompleteOperation = basketBallScript.dunkComplete;
if (dunkCompleteOperation == true)
{
Vector2 randomVector = new Vector2(Random.Range(-9f, 9f), Random.Range(0f, 3f));
Instantiate(Basket, randomVector, transform.rotation);
}
}
}
任何幫助將大大apreciated謝謝。
你能分享你的ball_script嗎?另外,是否只有一個球,或者你在扣籃之後產卵了? – ZayedUpal