0
我正處於一個遊戲工作的中間,而我剛剛開始。我在地圖上添加了png,並且在我想要無法通過的區域周圍添加了對撞機(它是2D平臺遊戲)。我有一個敵人已經設計並增加了2DRigidBody組件,因爲它四處移動,並開始使用2DBoxColliders作爲對撞機的水平,我的劇本我寫了:二維多邊形對撞機不會導致與二維多邊形對撞機碰撞
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sexapus : MonoBehaviour {
public static int Velocity = 42;
public Rigidbody2D rb;
public Vector2 dir;
public Animator anim;
void Start() {
rb = GetComponent<Rigidbody2D>();
dir = new Vector2(1, 0);
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
rb.velocity = dir * Velocity;
anim.SetFloat ("Direction", dir.x);
}
void OnCollisionEnter2D (Collision2D col) {
dir = dir * -1;
}
//CHECK TASKS
}
意味着敵人會撞到牆的一側,然後旋轉並開始轉向另一個方向。我意識到我的地圖大小使用多個2DBoxColliders(當我說多個時,我的意思是我可能需要使用一百多個),這是一個非常糟糕的方式。我現在已經開始爲地圖使用2DpolygonCollider,但現在敵人不會與牆壁碰撞並轉身,它只會朝向相同的方向,但不會移動。有人知道爲什麼