zoukankan      html  css  js  c++  java
  • C# 脚本

    1. C#里使用Find函数查找物体时要用 GameObject:
    GameObject.Find("Canvas/Text").GetComponent<Text>().text="Score";
    2. 用Instantiate初始化物体时要用 as Transform 转换类型(对于 Transform 类型而言)
    Transform Ball=Instantiate(newObject,transform.position,transform.rotation) as Transform;
    3. Rigidbody.velocity是初速度、可以用Vector3赋值。
    读取颜色要使用GetComponent<>():
    OriginalColor=GetComponent<Renderer>().material.color;
    用到Renderer的地方都要加GetComponent、这种情况还有很多…Audio→GetComponent<AudioSource>().…等、
    19中老师讲的就是用Find系列函数会拖慢程序运行速度、可以在Start函数中用变量保存一下Find的结果、用到时调用这个变量:
    Obj=GameObject.Find("Name");
    Obj=GameObject.FindWithTag("TagName");
    5. C#中结构体定义对象时要用new创建(不知是不是、不太确定)、比如 new Rect(…), new Vector3(…)等
    6. 脚本命令使用方法:
    [RequireComponent(typeof(CharacterController))]

  • 相关阅读:
    Android 手机摇一摇功能的实现
    Android 只开启一个Activity实例
    android 获取Datepicker日期
    帧动画
    进度条ProgressDialog
    AlertDialog错误
    ListView加checkBox可以实现全选等功能
    一些自己常用的工具类
    错层
    Parallax
  • 原文地址:https://www.cnblogs.com/Cocomo/p/5629607.html
Copyright © 2011-2022 走看看