Beispiel #1
0
 //Called by an Attack to notify the actor that the Attack is started
 public virtual void OnAttackStarted(Attack attack = null)
 {
 }
Beispiel #2
0
        private static void AddChargeProjectileAttack()
        {
            GameObject selectedObject = Selection.activeGameObject;
            RexActor   actor          = null;

            if (selectedObject)
            {
                actor = selectedObject.GetComponent <RexActor>();
            }

            GameObject attackGameObject = null;

            if (actor != null)
            {
                Transform attackTransform = actor.transform.Find("Attacks");
                if (attackTransform)
                {
                    attackGameObject = attackTransform.gameObject;
                }
            }

            if (attackGameObject == null && actor != null)
            {
                attackGameObject                  = new GameObject();
                attackGameObject.name             = "Attacks";
                attackGameObject.transform.parent = actor.transform;
            }

            if (actor != null)
            {
                Object     prefab = Resources.Load("Templates/ChargeProjectileAttackTemplate") as Object;
                GameObject projectileGameObject = Instantiate(prefab, SceneView.lastActiveSceneView.pivot, Quaternion.identity) as GameObject;
                projectileGameObject.name = "ChargeProjectileAttack";
                PrefabUtility.DisconnectPrefabInstance(projectileGameObject);
                projectileGameObject.transform.parent        = attackGameObject.transform;
                Selection.activeGameObject                   = projectileGameObject;
                projectileGameObject.transform.localPosition = new Vector3(1.94f, 0.0f, 0.0f);

                Attack attack = projectileGameObject.GetComponent <Attack>();
                attack.slots.actor          = actor;
                attack.slots.audio          = actor.GetComponent <AudioSource>();
                attack.slots.boxCollider    = attack.GetComponent <BoxCollider2D>();
                attack.slots.spriteRenderer = attack.GetComponentInChildren <SpriteRenderer>();

                ChargeProjectile chargeProjectile = attack.GetComponent <ChargeProjectile>();
                if (chargeProjectile != null)
                {
                    chargeProjectile.spriteToFlash = actor.slots.spriteRenderer;
                }

                if (actor.tag == "Enemy")
                {
                    attack.GetComponent <ContactDamage>().willDamagePlayer  = true;
                    attack.GetComponent <ContactDamage>().willDamageEnemies = false;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexActor component to attach this attack to first.", "Got it!");
            }
        }