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 = "熊猫头";
    }
}
相关推荐
ooo-p38 分钟前
FPGA学习篇——Verilog学习之“流水灯”
学习·fpga开发
代码游侠1 小时前
学习笔记——嵌入式系统通信基础及串口开发
运维·arm开发·笔记·单片机·嵌入式硬件·学习
小袁顶风作案1 小时前
leetcode力扣——452. 用最少数量的箭引爆气球
学习·算法·leetcode·职场和发展
2501_942326441 小时前
脑科学高效记忆法让学习变轻松
学习
cocodameyou1321 小时前
从能量阻滞到流动:解码“被动学习”背后的家庭动能重构逻辑
笔记·学习·其他·百度·微信·重构·课程设计
醇氧2 小时前
Spring WebFlux 学习
java·学习·spring
烤麻辣烫2 小时前
23种设计模式(新手)-9单例模式
java·开发语言·学习·设计模式·intellij-idea
TonyLee0172 小时前
新型学习范式(机器学习)
人工智能·学习·机器学习
代码游侠2 小时前
ARM嵌入式开发代码实践——LED灯闪烁(汇编版)
arm开发·笔记·嵌入式硬件·学习·架构
wheelmouse77882 小时前
Python 装饰器函数(decoratots) 学习笔记
笔记·python·学习