• Demon_接金币(三个掉落物品预设体,一接物体的工具)


    接物体的工具

    using UnityEngine;
    using System.Collections;
    
    public class Tool : MonoBehaviour {
    
        float hor;
    
        Vector3 moveDir;
    
        public float moveSpeed = 3f;
    
        int score = 0;
    
        void Update()
        {
            hor = Input.GetAxis ("Horizontal");
            //获取移动方向向量
            moveDir = hor * Vector3.right;
            //移动
            transform.position += moveDir * Time.deltaTime * moveSpeed;
        }
    
        void OnTriggerEnter(Collider other)
        {
            if (other.tag == "Gold") {
                Destroy (other.gameObject);
                Debug.Log (++score);
            }
        }
    
    }

    创建掉落体的三个预设体

    using UnityEngine;
    using System.Collections;
    
    public class GoldCreater : MonoBehaviour {
    
        //金币预设体
        public GameObject goldPrefab;
        //生成金币的时间间隔
        public float interval = 1f;
        //计时器
        private float timer;
        //索引号
        private int index;
    
        void Update()
        {
            //计时器计时
            timer += Time.deltaTime;
            //计时完成
            if (timer >= interval) {
                ///TODO:生成金币
                GoldInit();
                //计时器归零
                timer = 0;
            }
        }
    
        /// <summary>
        /// 生成金币
        /// </summary>
        void GoldInit()
        {
            //子对象索引号(随机)
            index = Random.Range (0, 3);
            //生成位置
            Vector3 initPos = transform.GetChild (index).position;
            //生成金币
            Instantiate (goldPrefab, initPos, Quaternion.identity);
        }
    
    
    }
  • 相关阅读:
    request对象
    js基础3
    Andorid Binder进程间通信---总结
    java 获取系统变量(环境变量和设置变量)
    參加项目管理培训的一些体会
    select poll使用
    关注关注工作行列
    jquery——zTree, 完美好用的树插件
    OSI七层模型具体解释
    (原创)优酷androidclient 下载中 bug 解决
  • 原文地址:https://www.cnblogs.com/VR-1024/p/6011143.html
Copyright © 2020-2023  润新知