【发布时间】:2017-05-12 13:38:21
【问题描述】:
首先,我知道这个问题被问了很多,但我找不到解决方案,所以我的问题是,我在做一个教育游戏,我有静脉和血流(有很多盒子碰撞器)和一个血细胞(也有一个盒子对撞机)但是我希望细胞在到达墙壁对撞机时被破坏,但它不只是停留在那里,这是项目!
http://tinypic.com/r/10706es/9
(由于我的名声,无法上传图片,抱歉)
我想摧毁我的细胞的对撞机是粉色对撞机,但是当它碰到它时它什么也不做,这是我的脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class collision : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnCollisionEnter(Collision col)
{
print("hihi");
if (col.gameObject.tag == "Collider")
{
Destroy(gameObject);
}
}
}
另外,这里是 AddForce 脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddForce : MonoBehaviour {
public float thrust;
public Rigidbody rb;
private Vector3 up;
private bool move;
void Start()
{
rb = GetComponent<Rigidbody>();
up = new Vector3(0, 1, 0);
move = false;
}
void FixedUpdate()
{
if (Input.GetKey("space"))
{
if (rb.velocity.magnitude < 5)
rb.AddForce(up * thrust);
move = true;
}
else
{
if (move == true)
rb.velocity = new Vector3(0, -0.5F, 0);
}
}
}
感谢你们的帮助! :D
【问题讨论】:
-
你是如何移动对象的?看起来那在您的 Addforce 脚本中。请发布该代码。
-
你确定你的对象被标记为“对撞机”吗?
-
100% 肯定,但是它不是标记为“collider”的对象,而是该对象有一个立方体子对象,并且该子对象具有盒子对撞机和“对撞机”标签,可以吗?问题?另外,我添加了“添加力”脚本