如何在与刚体体对象坠落碰撞后破坏运动物体

时间:2015-08-07 13:34:10

标签: c# android unity3d

之情况 我有一个带有球体对撞机的球体和另一个带有刚体问题的预制件,当我在触摸时移动球体然后球体在与坠落的rigibody对象碰撞后不会破坏。当我不移动物体然后它与之碰撞时只有detory detory坠落的刚体物体。

代码附加球体

            var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
        json.SerializerSettings.PreserveReferencesHandling =
            Newtonsoft.Json.PreserveReferencesHandling.All;

代码附加下降的rigibody正文对象

using UnityEngine;
using System.Collections;
public class moving : MonoBehaviour {
float speed=100f;
public GameObject hero;
void Start () {
    }
    // Update is called once per frame
void Update () {



            if (Input.touchCount > 0) {

            // The screen has been touched so store the touch
                    Touch touch = Input.GetTouch (0);



                    if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {

                            // If the finger is on the screen, move the object smoothly to the touch position
                            Vector3 touchPosition = Camera.main.ScreenToWorldPoint (new Vector3 (touch.position.x, touch.position.y, 100));                
                            transform.position = Vector3.Lerp (transform.position, touchPosition, Time.deltaTime * speed);

                    }

            }

    }

void OnCollisionEnter(Collision coll){

    Debug.Log(coll.gameObject.name);

    if (coll.gameObject.name == "Cube(Clone)") {
        Debug.Log(coll.gameObject.name);
            Destroy (hero); 
    }


}
    }

0 个答案:

没有答案