コード例 #1
0
    public override void Action()
    {
        //prevent action on cooldown not finished
        if (Time.time - lastUseTime < coolDown)
        {
            return;
        }

        GameObject   attack       = Instantiate(attackPrefab, player.transform.position, player.transform.rotation);
        BulletScript bulletScript = attack.GetComponent <BulletScript>();

        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        Vector2 direction = Vector3.Normalize(mousePosition - (Vector2)player.transform.position);

        bulletScript.SetAttributes(direction, speed);
        bulletScript.SetTimeout(lifeSpan, true, true);
        bulletScript.SetCallback(FinishAttack);
        SetCooldown();
    }