private static void AddProjectileAttack() { 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/ProjectileAttackTemplate") as Object; GameObject projectileGameObject = Instantiate(prefab, SceneView.lastActiveSceneView.pivot, Quaternion.identity) as GameObject; projectileGameObject.name = "ProjectileAttack"; 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>(); 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!"); } }
void Start() { #if UNITY_EDITOR useDebugInvincibility = EditorPrefs.GetBool("DebugInvincibility"); #endif if (useDebugInvincibility) { GameManager.Instance.useDebugInvincibility = true; player.GetComponent <RexActor>().invincibility.isDebugInvincibilityActive = true; } }
private static void FillRexActorSlots() { GameObject selectedObject = Selection.activeGameObject; RexActor actor = null; if (selectedObject) { actor = selectedObject.GetComponent <RexActor>(); } if (actor != null) { actor.slots.physicsObject = actor.GetComponent <RexPhysics>(); actor.slots.anim = actor.GetComponent <Animator>(); actor.slots.controller = actor.GetComponentInChildren <RexController>(); actor.slots.input = actor.GetComponent <RexInput>(); actor.slots.jitter = actor.GetComponent <Jitter>(); actor.slots.spriteHolder = actor.transform.Find("SpriteHolder"); actor.slots.spriteRenderer = actor.transform.Find("SpriteHolder").GetComponentInChildren <SpriteRenderer>(); if (actor.damagedProperties.spritesToFlash == null) { actor.damagedProperties.spritesToFlash = new List <SpriteRenderer>(); } actor.damagedProperties.spritesToFlash.Add(actor.slots.spriteRenderer); actor.slots.collider = actor.GetComponent <BoxCollider2D>(); RexPhysics physicsObject = actor.GetComponent <RexPhysics>(); if (physicsObject != null) { physicsObject.rexObject = actor; } RexController controller = actor.slots.controller; if (controller) { controller.slots.actor = actor; actor.waterProperties.landController = controller; } Energy[] energy = actor.GetComponentsInChildren <Energy>(); if (energy.Length > 0) { for (int i = 0; i < energy.Length; i++) { if (energy[i].gameObject.name == "HP") { actor.hp = energy[i]; } else if (energy[i].gameObject.name == "MP") { actor.mp = energy[i]; } } if (actor.hp == null) { actor.hp = energy[0]; } } Attack[] attacks = actor.GetComponentsInChildren <Attack>(); for (int i = 0; i < attacks.Length; i++) { attacks[i].slots.actor = actor; } EditorUtility.DisplayDialog("Yeah!", "The RexActor was successfully slotted!", "Yay!"); } else { EditorUtility.DisplayDialog("Ruh-roh!", "Please select a GameObject with a RexActor component first.", "Got it!"); } }