unity学习(40)——创建(create)角色脚本(panel)——UI

1.点击不同的头像按钮,分别选择职业1和职业2,create脚本中对应的函数。

2.调取inputfield中所输入的角色名(限制用户名长度为7字符),但愿逆向的服务器可以查重名:

3.点击头衔,显示选择的职业:(视频审核之后补上)

创建角色

函数代码如下(就是简单的设置static变量):

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class CreatePlayerPanel : MonoBehaviour
{
    //TMP_Text a = GameObject.FindWithTag("username").GetComponent<TMP_Text>();--不能写这里
    public static GameObject panel;//这是个全局变量--实例类
    private static int job=0;//当前所选角色
    //public static GameObject jobShow;
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("CreatePlayerPanel获取object测试--这个在游戏加载的时候就执行了,最最最开始大的时候");
        panel = GameObject.FindWithTag("createPanel");//同一命名空间即可,canvas在最外边是有道理的
        panel.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void finish()
    {
        //panel.SetActive(false);//点击
        //收取角色名
        TMP_Text nicknameCreate = GameObject.FindWithTag("nicknameCreate").GetComponent<TMP_Text>();
        Debug.Log(nicknameCreate.text);
        Debug.Log(job);
        panel.SetActive(false);//都接收完再隐藏,要不找不到--panel是个实例类,不用急
        if (nicknameCreate.text.Length < 16 && job != 0)
        {
            //跳转到游戏场景
            Debug.Log("跳转到游戏场景");
        }
        else 
        {
            Debug.Log("请按规定输入");
        }
        //最后跳转到游戏场景中

    }
    public void selectJob(int job)//职业-我就纳闷昵称在哪里
    {
        //选择职业
    }
    //点击按钮选择不同的角色--
    public void j1()
    {
        job = 1;//static 1号职业
        TMP_Text c = GameObject.FindWithTag("jobShow").GetComponent<TMP_Text>(); ;//得到两个Text对象
        c.text = "纸片人";
    }
    public void j2()
    {
        job = 2;//static 1号职业
        TMP_Text c = GameObject.FindWithTag("jobShow").GetComponent<TMP_Text>(); ;//得到两个Text对象
        c.text = "熊猫头";
    }
}
相关推荐
寒月小酒9 小时前
第三章 索引构建(2-all -in-rag学习)
学习
天国梦9 小时前
中学生居家英语听力训练深度解析:从核心痛点到AI赋能的全链路方案
人工智能·学习
胡渠洋13 小时前
postman学习
学习·测试工具·postman
Amazing_Cacao14 小时前
CFCA精品可可产区风土解析(美洲):无情打破风味堆叠假象,建立时间轴上的层次动态阅读系统
学习
六点_dn15 小时前
Linux学习笔记-shell运算符
linux·笔记·学习
其实防守也摸鱼15 小时前
渗透--损坏的对象级别鉴权漏洞(Broken Object Level Authorization, BOLA)
大数据·网络·数据库·学习·tcp/ip·安全·安全威胁分析
念雨思15 小时前
信用卡权益对比:基于HarmonyOS + ArkTS的AI智能金融助手开发实践
人工智能·学习·华为·金融·harmonyos·鸿蒙
铅笔侠_小龙虾16 小时前
Rust 学习(2)-变量、常量与 shadowing
学习·算法·rust
it小生010116 小时前
从底层思维到高效行动,顶尖人才进阶核心修炼指南
学习·学习方法
恣逍信点16 小时前
《凌微经》通俗解读——哲学第一因
学习·职场和发展·创业创新·学习方法·业界资讯·交友·哲学