sendmessage宣称“没有回收者”统一

发布于 2025-02-11 21:36:56 字数 2189 浏览 0 评论 0原文

我创建了两个游戏对象,一个名为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文