zoukankan      html  css  js  c++  java
  • [unity菜鸟] 笔记1 —— 函数篇

    SendMessage()  

    调用其他物体中的指令,先在脚本中编写一个自定义的函数,然后使用SendMessage()命令来调用那个物体上的命令

    //①将以下函数附给target对象
    
    void Renamer(string newName)
    {
        gameObject.name=newName;     
    }
    
    //②在其他脚本上调用这个函数
    
    GameObject.Find("target").SendMessage("Renamer","target_down");
    

    移动平台编程注意

    //使用这样的代码风格为移动平台编程时,把上述方法分两步很重要
    GameObject.Find("target").GetComponent<Setter>().Renamer("target_down");
                                      
                                       ↓
    GameObject theTarget = GameObject.Find("target");
    theTarget.GetComponent<Setter>().Renamer("target_down");
    

      

     Update()和FixedUpdate()

    FixedUpdate() 与物理引擎保持同步,函数每秒被调用的次数是固定。当我们使用与物理相关的脚本时,它更适合,如刚体的使用和重力效果。

    Update()函数取决于帧数,每秒被调用的次数取决于硬件本身的性能。

     

    Input.GetAxis

    确定移动方向的,Input.GetAxis("Horizontal")是在X轴上移动,Input.GetAxis("Vertical")代表在z轴上移动

    Unity中 Move 和 SimpleMove 区别                                                                       (参考)

    总结如下:

    Move: 不受重力影响, 受到collider的阻挡。 Move(new Vector(0, 0, 1)) --- 向z轴移动动一单位

    SimpleMove: 受到重力影响, 也受到collider阻挡, SimpleMove(new Vector(0, 0 ,1)); ----向z轴移动 Time.deltaTime * 1单位的距离。

    Quaternion.LookRotation

    InvokeRepeating

    void Start()
    {
          //0表示现在开始调用,1表示每一秒都调用一次repeat()函数
          InvokeRepeating("repeat",0,1);  
    }    
    
    void repeat()
    {
          Debug.log(" I am repeating every second");      
    }
    

    Instantiate  实例                                                                                                 (参考)

    static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object

    描述:克隆原始物体并返回克隆物体。

  • 相关阅读:
    springmvc的控制器是不是单例模式,如果是,有什么问题,怎么解决?
    数据库中的锁机制
    在inux中安装redis的时候,会出现下面的这个异常
    使用SecureCRT操作linux系统时候的简单设置
    装饰者设计模式
    java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.
    事务
    2.6.1 测试架构师
    测试专家讲述通往测试架构师之路
    什么是软件测试架构师
  • 原文地址:https://www.cnblogs.com/code1992/p/3675105.html
Copyright © 2011-2022 走看看