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();
	}
	
	// Update is called once per frame
	void Update () {
		
	}
    void OnCollisionEnter(Collision c)
    {
        c.gameObject.GetComponent().material.color = Color.red;
        Debug.Log("fuck1");
        fuck.material.color = Color.red;
    }
    void OnCollisionExit(Collision c)
    {
        c.gameObject.GetComponent().material.color = Color.yellow;
        //fuck.material.color = Color.red;
        Debug.Log("fuck2");
    }
}
需要装刚体/碰撞体组件,明天再仔细研究一波

你可能感兴趣的:(unity3D)