《Unity API常用方法和类详细讲解—Siki学院》课程学习笔记02

《Unity API常用方法和类详细讲解—Siki学院》课程学习笔记02

课时10 GameObject、Component和Object的千丝万缕的关系
在这里插入图片描述
一个游戏由多个场景组成,一个场景由多个游戏物体(GameObject)组成,一个游戏物体由多个组件组成(Component);
在这里插入图片描述
组件:Transform, Rigidboy, MeshRender, MeshFilter, Collider, NavmeshAgent, Animation, Animator,自定义脚本(Script)
在这里插入图片描述
课时11-12 UnityEngine下Object的静态方法以及GameObject独有的静态方法
Destroy():可以销毁游戏物体和组件;
DontDestroyOnLoad(gameobject):设置共享的游戏物体,重新调整场景时不会销毁;
FindObjectOfType()根据类型获取组件;
FindObjectsOfType()根据类型返回组件数组;
在这里插入图片描述
GameObject.Find(“Main Camera”);根据名称获得主相机;
GameObject.FindGameObjectsWithTag(“Main Camera”);根据标签获得主相机;

课时13 游戏物体间消息的发送和接收
(1)GameObject.BroadcastMessage(string methodName, object parameter = null, SendMessageOptions options = SendMessageOptions.RequireReceiver); //发送该节点的所有子节点
(2)GameObject.SendMessage(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver); //发送给物体本身
(3)GameObject.SendMessageUpwards(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver); //发送给其所有父节点

课时14得到组件各种方法函数:
GetComponent<组件类型>();
GetCompoents<组件类型>();
GetCompoentsInChilren<组件类型>();
GetComponentsInChildren<组件类型>();
GetComponentInParent<组件类型>();
GetCompoentsInParent<组件类型>();

课时15-17MonoBehavior部分总结
在这里插入图片描述
(1)得到组件的各种方法函数
GetComponent;只会得到在游戏物体身上的第一个检测到的组件
GetComponent;会得到物体上所有的组件
GetComponentInChildren;会得到其自身及其子物体身上第一个检测到的相应的组件
GetComponentInParent;会得到其自身及其父物体身上第一个检测到的相应的组件
GetComponentsInChildren;会得到其自身及其子物体身上所有检测到的相应的组件
GetComponentsInParent;会得到其自身及其父物体身上所有检测到的相应的组件
(2)公共函数
Public void Invoke(string methodName,float time );延时调用函数
CancelInvoke;取消所有调用的函数(仅适用于当前脚本)
InvokeRepeating;重复调用函数
(3)Invoke的使用详解

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class API07Invock : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
       // Invoke("Attack",3);
        InvokeRepeating("Attack",3,5);
        CancelInvoke();
    }
    // Update is called once per frame
    void Update()
    {
        bool res=IsInvoking("Attack");
        print(res);
    }
    void Attack() 
    {
        print("开始攻击");
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值