zoukankan      html  css  js  c++  java
  • unity碰撞检测(耗费性能)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PengZhuang : MonoBehaviour {
        public int lingLi = 100;
        System.Timers.Timer timer = new System.Timers.Timer();
        private bool isStay = true;
    	// Use this for initialization
    	void Start () {
    		
    	}
    	
    	// Update is called once per frame
    	void Update () {
    		
    	}
    
        void OnCollisionEnter(Collision col)
        {
            if (timer.Enabled == false) {
                timer.Interval = 1000;
                timer.Enabled = true;
                timer.Elapsed += (a, b) => stayEvent();
            }
            
            col.gameObject.GetComponent<Renderer>().material.color = Color.red;
            Debug.Log("开始碰撞" + col.collider.gameObject.name);
        }
        void OnCollisionStay(Collision col)
        {
        }
        void OnCollisionExit(Collision col)
        {
            isStay = false;
            timer.Stop();
            timer.Close();
            Debug.Log("碰撞结束" + col.collider.gameObject.name);
        }
    
        void stayEvent() {
            if (isStay && lingLi >=0) {
                lingLi--;
                //Vector3 v = gameObject.transform.localScale;
                //v.x = v.x * lingLi / 100;
                //v.y = v.y * lingLi / 100;
                //v.z = v.z * lingLi / 100;
                //gameObject.transform.localScale = v;
                Debug.Log("持续碰撞中");
            }
        }
    
    }
    
  • 相关阅读:
    学习python第二天数据库day1
    学习python第一天总纲
    Mac 键盘快捷键
    报错 Filtered offsite request
    mysql 顺序问题
    implode 把数组 组成一个字符串
    TP view中跳转到某个控制器
    生成商品的唯一货号
    数组排序
    判断文件是否存在 删除文件
  • 原文地址:https://www.cnblogs.com/xiaoguangit/p/11277641.html
Copyright © 2011-2022 走看看