This commit is contained in:
Gerard Gascón 2025-04-24 16:56:52 +02:00
commit 862afc9b7a
478 changed files with 197737 additions and 0 deletions

View file

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoombaAI : hasHP
{
Rigidbody2D rb;
public GameObject itemDrop;
private Vector2 dir;
private Vector2 length;
void Start()
{
length = GetComponent<SpriteRenderer>().bounds.size;
curHP = MaxHP;
rb = gameObject.GetComponent<Rigidbody2D>();
dir = new Vector2(-1, 0);
}
// Update is called once per frame
void Update()
{
transform.rotation = Quaternion.Euler(0, rb.velocity.x < 0 ? 180 : 0, 0);
if (rb.velocity.magnitude < 0.1) { rb.velocity += new Vector2(0, 5f); }
bool hit = Physics2D.Raycast(gameObject.transform.position, dir, (length.x / 2) + 0.1f, 1 << LayerMask.NameToLayer("Ground")) || !Physics2D.Raycast(gameObject.transform.position + (Vector3.right * dir.x * ((length.x / 2) + 0.1f)), Vector3.down, (length.y / 2) + 0.1f, 1 << LayerMask.NameToLayer("Ground"));
if(hit) {
dir *= -1;
}
rb.velocity = dir + new Vector2(0,rb.velocity.y);
}
private void OnCollisionEnter2D(Collision2D collision) {
if (collision.collider.name.Equals("Player")) {
collision.collider.gameObject.GetComponent<PlayerStats>().Die();
}
}
public override void die() {
gameObject.GetComponent<Dropper>().Ammo();
Object.Destroy(gameObject);
}
}