unity3D 碰撞检测例子代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Collisiotest : MonoBehaviour {
    private Renderer fuck;
	// Use this for initialization
	void Start () {
        fuck = GetComponent<Renderer>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}
    void OnCollisionEnter(Collision c)
    {
        c.gameObject.GetComponent<Renderer>().material.color = Color.red;
        Debug.Log("fuck1");
        fuck.material.color = Color.red;
    }
    void OnCollisionExit(Collision c)
    {
        c.gameObject.GetComponent<Renderer>().material.color = Color.yellow;
        //fuck.material.color = Color.red;
        Debug.Log("fuck2");
    }
}
需要装刚体/碰撞体组件,明天再仔细研究一波

猜你喜欢

转载自blog.csdn.net/animalcoder/article/details/80602887