unity 控制Dropdown的Arrow箭头变化

Dropdown打开下拉菜单会以"Template"为模板创建一个Dropdown List,在"Template"上添加一个脚本在Start()中执行下拉框打开时的操作,在OnDestroy()中执行下拉框收起时的操作即可。

效果代码如下用于控制Arrow旋转可以根据自己的想法进行修改:

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

/// <summary>
/// 控制Dropdown中的Arrow效果,脚本挂在Template上
/// </summary>
public class DropdownArrowCtr : MonoBehaviour
{
    public RectTransform arrow;
    // Start is called before the first frame update
    void Start()
    {
        if (this.name == "Dropdown List")
        {
            arrow.eulerAngles = new Vector3(0, 0, 180);
        }
    }

    private void OnDestroy()
    {
        if (this.name == "Dropdown List")
        {
            arrow.eulerAngles = Vector3.zero;
        }
    }
}
相关推荐
zhchyun20081 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(03)
unity
淡海水2 天前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
郝学胜-神的一滴2 天前
中级OpenGL教程 030:gl_FragCoord解锁区域渲染与深度可视化新姿势
c++·unity·游戏引擎·图形渲染·unreal engine·opengl
ellis19702 天前
u3d插件xLua[四]Lua访问C#源码分析,反射,生成代码
unity
2401_894915532 天前
GEO 定位优化源码搭建常见报错排查:数据库、伪静态、接口调试
java·数据库·网络协议·tcp/ip·spring·unity
xcLeigh3 天前
Unity基础:C#脚本的创建与挂载——让你的游戏物体活起来
游戏·unity·c#·教程
DaLiangChen4 天前
Vuforia 地面识别案例
unity·ar