sendmessage宣称“没有回收者”统一
我创建了两个游戏对象,一个名为TextBox,另一个名为Toutch。这些游戏对象中的每一个都比收到自己的C#脚本。分配了文本框对象:npctext.cs和另一个对象toutch被分配了toutchpepper.cs:
toutchpepper cs文件:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToutchPepper : MonoBehaviour
{
public GameObject self;
private bool onObject=false;
public GameObject textBox;
void Start()
{
self.SetActive(true);
}
void OnMouseEnter()
{
onObject = true;
}
void OnMouseExit()
{
onObject = false;
}
void Update(){
Debug.Log(onObject+"pepper");
if(Input.GetMouseButtonDown(0))
{
if(onObject){
textBox.GetComponent<NPCtext>().SendMessage("chiliPepper");
}
}
}
}
npctext.cs:
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using System.Collections;
public class NPCtext : MonoBehaviour
{
[SerializeField]private TextMeshProUGUI DIALOUGE;
[SerializeField]public TextMeshProUGUI Name;
[SerializeField]private Sprite[] NPCS;
[SerializeField]public Image NPC_IMAGE;
public static string pause="True";
[SerializeField]public GameObject main;
private int DioOn=0;
private string[] names={"eylmo","poopoohead","redPepper","yellowPepper"};
private string[] startDio={"hello","there"};
void Start()
{
sayText();
}
public void setText(string x, int y)
{
main.SetActive(true);
DIALOUGE.text=x;
NPC_IMAGE.sprite=NPCS[y];
Name.text=names[y];
}
void sayText()
{
setText(startDio[DioOn],0);
}
public void Next(){
//Debug.Log(DioOn<startDio.Length);
if(DioOn<startDio.Length-1){
pause="True";
DioOn+=1;
sayText();
}else{
pause="False";
main.SetActive(false);
}
}
public void chiliPepper(){
Debug.Log("oki");
}
}
现在,如您所见,您正在尝试使用sendmessage,要求使用chilipepper void void void,但这只是给我一个错误:
sendmessage chilipepper没有接收器! unityEngine.component:sendmessage(string)
I created two game objects, one which was named textBox, and another named Toutch. Each of these game objects than recieved their own c# script. The textBox object was assigned: NPCtext.cs and the other object, Toutch, was assigned ToutchPepper.cs:
ToutchPepper cs file:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToutchPepper : MonoBehaviour
{
public GameObject self;
private bool onObject=false;
public GameObject textBox;
void Start()
{
self.SetActive(true);
}
void OnMouseEnter()
{
onObject = true;
}
void OnMouseExit()
{
onObject = false;
}
void Update(){
Debug.Log(onObject+"pepper");
if(Input.GetMouseButtonDown(0))
{
if(onObject){
textBox.GetComponent<NPCtext>().SendMessage("chiliPepper");
}
}
}
}
NPCtext.cs:
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using System.Collections;
public class NPCtext : MonoBehaviour
{
[SerializeField]private TextMeshProUGUI DIALOUGE;
[SerializeField]public TextMeshProUGUI Name;
[SerializeField]private Sprite[] NPCS;
[SerializeField]public Image NPC_IMAGE;
public static string pause="True";
[SerializeField]public GameObject main;
private int DioOn=0;
private string[] names={"eylmo","poopoohead","redPepper","yellowPepper"};
private string[] startDio={"hello","there"};
void Start()
{
sayText();
}
public void setText(string x, int y)
{
main.SetActive(true);
DIALOUGE.text=x;
NPC_IMAGE.sprite=NPCS[y];
Name.text=names[y];
}
void sayText()
{
setText(startDio[DioOn],0);
}
public void Next(){
//Debug.Log(DioOn<startDio.Length);
if(DioOn<startDio.Length-1){
pause="True";
DioOn+=1;
sayText();
}else{
pause="False";
main.SetActive(false);
}
}
public void chiliPepper(){
Debug.Log("oki");
}
}
Now, as you can see I am trying to use SendMessage, asking to use the chiliPepper void, but it just gives me an error:
SendMessage chiliPepper has no receiver!
UnityEngine.Component:SendMessage (string)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论