触发对象时是否显示文字消息?

问题描述

我正在制作一个我想要的图书馆互动地图,以便当玩家接触并触发围绕地图的不可见对象时,显示消息的文本将落到他的视图中,然后他可以按Enter键当我尝试运行代码时,控制台将返回“我无法修改'Transform.position'的返回值,因为它不是变量”,因此它将备份。也许这与文本是“ RectTranform”而不是“ Transform”有关,我不知道

以下是触发代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//I misspelled collision but that doesn't matter
public class collsiion : MonoBehaviour
{
    void OnTriggerEnter(){
         FindObjectOfType<messageToggle>().goingdown();
    }
     
}

这是消息移动代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class messageToggle : MonoBehaviour
{
   public RectTransform _message;

   public bool gru = false;

   public float brumium = 50f;
   public void goingdown(){
        _message.posY =- brumium;
        gru = true;
   }
   void Update()
    {
        if(gru == true){
            if(Input.GetKey("f")){
                //by the way does anyone know how to put Enter key as an input
                _message.position.y =+ brumium;
            }     
        }
    }
}    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)