Skip to content

Pugmob #141

@almayaliaalmayali-svg

Description

@almayaliaalmayali-svg

using UnityEngine;

public class Dagger : MonoBehaviour
{
private Rigidbody2D rb;
private bool hasHit = false;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
}

void Update()
{
    // جعل الخنجر يتجه دائماً نحو اتجاه حركته (واقعية)
    if (!hasHit && rb.linearVelocity.magnitude > 0.1f)
    {
        float angle = Mathf.Atan2(rb.linearVelocity.y, rb.linearVelocity.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
}

private void OnCollisionEnter2D(Collision2D collision)
{
    hasHit = true;
    rb.linearVelocity = Vector2.zero; // يتوقف عند الاصطدام
    rb.isKinematic = true; // لكي لا يسقط بعد الاصطدام بالكرتونة

    if (collision.gameObject.CompareTag("Crate"))
    {
        // كود لتدمير الكرتونة أو دفعها
        Debug.Log("اصطدم بالكرتونة!");
        transform.SetParent(collision.transform); // الخنجر ينغرس في الكرتونة
    }
    else if (collision.gameObject.CompareTag("Player"))
    {
        Debug.Log("إصابة مباشرة للخصم!");
        // هنا تضع كود نقص الحياة HP
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions