오브젝트가 파손되었을 때 다른 스크립트 메소드 (별)를 호출하려고합니다. 아래 코드는 지금까지 수행 한 작업입니다. "tim.stars"라인에서 오류 (Null 참조)가 발생했습니다. , 내가 뭘 잘못했는지 어떤 제안? 여기 내 코드가있다.다른 스크립트에서 호출하는 메소드 C# Unity3d
using UnityEngine;
using System.Collections;
public class clear : MonoBehaviour {
// Use this for initialization
void Start() {
GetComponent<ParticleSystem>().emissionRate = 0;
}
// Update is called once per frame
void Update() {
if (Input.GetMouseButtonDown (1)) {
GetComponent<ParticleSystem>().Emit (10);
}
}
void OnParticleCollision(GameObject obj)
{
if (obj.gameObject.tag == "fire1") {
Destroy (obj, 5.0f);
TimingForIndust2 tim = GetComponent<TimingForIndust2>();
tim.stars();
}
StartCoroutine (TestCoroutine());
}
IEnumerator TestCoroutine(){
yield return new WaitForSeconds(8);
Application.LoadLevel (25);
}
}
여기에 귀하의 코멘트를 읽어 TimingForIndust2
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using MadLevelManager;
public class TimingForIndust2 : MonoBehaviour {
public Transform TimingBar;
public Transform TextIndicator;
public Transform TextRemaining;
[SerializeField] private float currentAmount;
[SerializeField] private float speed;
// method to reduce the time continously
void Update() {
if (currentAmount > 0) {
currentAmount -= speed*Time.deltaTime;
TextIndicator.GetComponent<Text>().text=((int)currentAmount).ToString()+"s";
TextRemaining.gameObject.SetActive(true);
} else {
TextRemaining.gameObject.SetActive(false);
TextIndicator.GetComponent<Text>().text="TimeUP";
Application.LoadLevel (62);
}
TimingBar.GetComponent<Image>().fillAmount = currentAmount/60;
}
public void stars()
{
if (currentAmount > 45.0f) {
MadLevelProfile.SetLevelBoolean (MadLevel.currentLevelName, "star_1", true);
MadLevelProfile.SetLevelBoolean (MadLevel.currentLevelName, "star_2", true);
MadLevelProfile.SetCompleted (MadLevel.currentLevelName, true);
} else if (currentAmount > 20.0f && currentAmount < 29.0f) {
MadLevelProfile.SetLevelBoolean (MadLevel.currentLevelName, "star_1", true);
MadLevelProfile.SetLevelBoolean (MadLevel.currentLevelName, "star_2", true);
MadLevelProfile.SetCompleted (MadLevel.currentLevelName, true);
} else if (currentAmount > 2.0f && currentAmount < 19.0f) {
MadLevelProfile.SetLevelBoolean (MadLevel.currentLevelName, "star_1", true);
}
}
}
동일한 게임 객체에 'TimingForIndust2' 스크립트가 첨부되어 있습니까 ('clear')? 또는'TimingForIndust2'가 충돌을 감지 할'fire1' 태그를 사용하여 gameobject에 첨부되어 있습니까? – Programmer
clear 스크립트에는 my (소화기 prefeb)가 인벤토리에서로드되고 TimingForIndust2 스크립트가 Timer에 연결됩니다 (타이머는 실제로 시간이 실행되는 캔버스 임). 클리어 스크립트 및 TimingForIndust2 스크립트가 다른 개체에 연결되어 있습니다. @Programmer –