Unity中的苍蝇拍运动

时间:2016-08-03 22:39:53

标签: c# unity3d game-physics unity5

我正在创造一个团结游戏(我的第一个2D游戏),这个游戏的想法是使用苍蝇拍杀死苍蝇,但问题是在苍蝇运动(从上到下)和苍蝇拍与苍蝇之间的碰撞飞。

这是我的代码,但我不知道为什么碰撞不起作用

using UnityEngine;
using System.Collections;

public class SwatterController : MonoBehaviour {

public float speed = 1.5f;
private Vector3 target;

void Start () {
    target = transform.position;
}

void Update () {
//Movement of swatter when I click on the screen
    if (Input.GetMouseButtonDown(0)) {
        target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        target.z = transform.position.z;
    }
    transform.position = Vector3.MoveTowards(transform.position, target, speed * 5);
} 

void OnCollisionEnter2D(Collision2D other){
    Debug.Log ("dead");
}
} 

我想知道我的代码如何正确移动苍蝇拍(苍蝇拍放在相机后面) 如果你有一个例子,请发布它。

使用的物体:飞(圆形对撞机2D),苍蝇拍(盒式对撞机2D)

0 个答案:

没有答案