Forum begins after the advertisement:


When an enemy is killed using a clock lancet, XPGEM does not disappear

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity When an enemy is killed using a clock lancet, XPGEM does not disappear

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #15939
    Helpful?
    Up
    0
    ::

    null

    When an enemy is killed using a clock lancet, XPGEM does not disappear.
    When I used another weapon to kill the enemy, I confirmed that the XPGEM was normally absorbed and disappeared.
    Have you ever experienced a similar phenomenon?

    IceBeam is Clock Lancet in My Project.

    using UnityEngine;
    
    public class IceBeamWeapon : ProjectileWeapon
    {
        public const int NUMBER_OF_ANGLES = 12;
        protected float currentAngle = 90;
    
        protected static float turnAngle = -360f / NUMBER_OF_ANGLES;
    
        protected override bool Attack(int attackCount = 1)
        {
            if (base.Attack(1))
            {
                currentAngle += turnAngle;
    
                if(Mathf.Abs(currentAngle) > 180f)
                    currentAngle = -Mathf.Sign(currentAngle) * (360f - Mathf.Abs(currentAngle));
    
                return true;
            }
            return false;
        }
    
        protected override float GetSpawnAngle() { return currentAngle; }
    }

    PickUp.cs

    using UnityEngine;
    
    public class Pickup : Sortable
    {
        public float lifespan = 0.5f;
        protected PlayerStats target; // If the pickup has a target, then fly towards the target.
        protected float speed; // The speed at which the pickup travels.
        Vector2 initialPosition;
        float initialOffset;
    
        // To represent the bobbing animation of the object.
        [System.Serializable]
        public struct BobbingAnimation
        {
            public float frequency;
            public Vector2 direction;
        }
        public BobbingAnimation bobbingAnimation = new BobbingAnimation
        {
            frequency = 2f,
            direction = new Vector2(0, 0.3f)
        };
    
        [Header("Bonuses")]
        public int experience;
        public int health;
    
        protected override void Start()
        {
            base.Start();
            initialPosition = transform.position;
            initialOffset = Random.Range(0, bobbingAnimation.frequency);
        }
    
         protected virtual void Update()
        {
            if (target)
            {
                Vector2 distance = target.transform.position - transform.position;
    
                if (distance.sqrMagnitude > speed * speed * Time.deltaTime)
                    transform.position += (Vector3)distance.normalized * speed * Time.deltaTime;
                else
                    Destroy(gameObject);
            }
            else
            {
                transform.position = initialPosition + 
                    bobbingAnimation.direction * 
                    Mathf.Sin((Time.time + initialOffset) * bobbingAnimation.frequency);
            }
        }
    
        public virtual bool Collect(PlayerStats target, float speed, float lifespan = 0f)
        {
            if(!this.target)
            {
                this.target = target;
                this.speed = speed;
                if(lifespan > 0)
                    this.lifespan = lifespan;
                Destroy(gameObject, Mathf.Max(0.01f, this.lifespan));
    
                return true;
            }
    
            return false;
        }
    
        protected virtual void OnDestroy()
        {
            if (!target) return;
    
            if(experience != 0) target.IncreaseExperince(experience);
            
            if(health != 0) target.RestoreHealth(health);
        }
    }
    #15942
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    The only times DropRateManager will not spawn a drop is when the active property is disabled, or when a scene is not finished loading.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DropRateManager : MonoBehaviour
    {
        [System.Serializable]   //Serialize the class
        public class Drops
        {
            public string name;
            public GameObject itemPrefab;
            public float dropRate;
        }
        public bool active = false;
        public List<Drops> drops;
    
        void OnDestroy()
        {
            if (!active) return;
            if (!gameObject.scene.isLoaded) //Stops the spawning error from appearing when stopping play mode
            {
                return;
            }
    
            float randomNumber = UnityEngine.Random.Range(0f, 100f);
            List<Drops> possibleDrops = new List<Drops>();
    
            foreach (Drops rate in drops)
            {
                if (randomNumber <= rate.dropRate)
                {
                    possibleDrops.Add(rate);
                }
            }
            //Check if there are possible drops
            if (possibleDrops.Count > 0)
            {
                Drops drops = possibleDrops[UnityEngine.Random.Range(0, possibleDrops.Count)];
                Instantiate(drops.itemPrefab, transform.position, Quaternion.identity);
            }
        }
    }

    You might want to pause the game and check the DropRateManager component on your frozen enemies and see if any of the properties are modified when they are frozen.

    #15943
    Helpful?
    Up
    0
    ::
    List<Drops> possibleDrops = new List();

    Assets\02. Scripts\DropRateManager.cs(28,41): error CS0305: Using the generic type ‘List<T>’ requires 1 type arguments

    List<Drops> possibleDrops = new List<Drops>(); 

    Is it Right?

    #15944
    Helpful?
    Up
    0
    ::

    I think it’s a pretty bad situation. I can’t find any particular difference. I need to check more.

    #15952
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    My bad, I made a mistake with the script. You are missing the type argument highlighted below:

    List<Drops> possibleDrops = new List<Drops>();
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: