我试图重建超级马里奥兄弟的第一阶段,但是我在Koopa Shells之间的碰撞系统上遇到了一些麻烦。
我写了两个不同的脚本,希望达到这个目的:
这第一个脚本是处理基本运动,并开始在球员碰撞壳运动
public class KoopaShell : MonoBehaviour { //Makes this accessible to other Scripts static public bool Moving; // Boolean Flags to be inherited public bool isMoving; bool shellLeft, shellRight, rightBlocked, leftBlocked; public float rayDis; public LayerMask enemyMask; public Transform rCast; BoxCollider rayHold; ConstantForce2D cf; float myWidth, myHeight; Rigidbody2D rb; Ray rRay, lRay; Transform myTrans; Vector2 myVel; [SerializeField] RaycastHit hitinfo; // Start is called once at the beginning of run time void Start() { // Sets our shorthanded variables equal to the KoopaShell's Rigid Body and position; myTrans = this.transform; rb = this.gameObject.GetComponent(); //Ignores Collision Between the level boundaries/ power ups and the Koppa Shell Physics2D.IgnoreLayerCollision(9, 12); Physics2D.IgnoreLayerCollision(11, 12); // This is a variable to help short hand us accessing our Sprite Renderer component SpriteRenderer mySprite = this.gameObject.GetComponent(); // These two variables are using the mySprite varaible to access the extents or total midway point of the sprite in both the x and y axis myWidth = mySprite.bounds.extents.x;