using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Destroy : MonoBehaviour {
private Transform m_transform;
// Use this for initialization
void Start () {
m_transform = gameObject.GetComponent<Transform>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A)) {
m_transform.Translate(Vector3.left * 5 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D)) {
m_transform.Translate(Vector3.right * 5 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W)) {
m_transform.Translate(Vector3.forward * 5 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S)) {
m_transform.Translate(Vector3.back * 5 * Time.deltaTime);
}
}
void OnCollisionEnter(Collision other) {
if (other.gameObject.name == "Cube") {
Debug.Log("销毁" + other.gameObject.name);
Destroy(other.gameObject);
}
}
}
Unity3D学习记录——碰撞销毁物体
最新推荐文章于 2025-03-05 15:44:08 发布
本文介绍了一个使用Unity实现的游戏对象移动与碰撞销毁的简单示例。通过键盘输入控制游戏对象移动,并在与名为“Cube”的对象发生碰撞时销毁该对象。文章提供了完整的C#脚本代码,展示了如何在游戏开发中实现基本的移动和碰撞响应。
6920

被折叠的 条评论
为什么被折叠?



