zoukankan      html  css  js  c++  java
  • unity脚本教程笔记02

    事件

    public class Shijian : MonoBehaviour
    {
    // Start is called before the first frame update
    public delegate void click();//定义委托
    public static event click cl;//定义事件
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.F))
    {
    cl();//执行事件
    }
    }
    }

    **********

    public class Yidong : MonoBehaviour
    {
    // Start is called before the first frame update
    private void OnEnable()
    {
    Shijian.cl += Teleport;//将方法订阅到事件
    }
    void Start()
    {

    }
    private void OnDisable()
    {
    Shijian.cl -= Teleport;
    }
    // Update is called once per frame
    void Update()
    {

    }
    void Teleport()
    {
    Vector3 pos = transform.position;
    pos.y = Random.Range(1.0f, 3.0f);//随机值1到3之间
    transform.position = pos;
    }
    }

  • 相关阅读:
    HDU 1556 差分,前缀和
    Full permutation
    PAT B1029
    字串简介
    阵列(3)
    完形填空
    关于c的比较
    19 阵列的复制
    switch述句
    阵列变数(2)
  • 原文地址:https://www.cnblogs.com/tilyougogannbare666/p/12960715.html
Copyright © 2011-2022 走看看