void Awake() { //Gets Animator Animation = GetComponent <Animator>(); // Makes a hitbox for the player, and adds all components to make it AttackHitBox = new GameObject(); AttackHitBox.AddComponent <SpriteRenderer>(); AttackHitBox.AddComponent <Animator>(); AttackHitBox.GetComponent <SpriteRenderer>().sprite = AttackSprite; player = GameObject.FindGameObjectWithTag("Player"); AttackHitBox.name = "AttackHitBox"; AttackHitBox.tag = "AttackHitBox"; AHBRigid2D = AttackHitBox.AddComponent <Rigidbody2D>(); AHBRigid2D.gravityScale = 0; // Adds script to check to see if it hits an enemy AHBScript = AttackHitBox.AddComponent <AttackHitBox>(); AHitBoxCollider = AttackHitBox.AddComponent <BoxCollider2D>(); AHitBoxCollider.offset = new Vector2(0f, 0f); AHitBoxCollider.size = new Vector2(0.15f, 0.15f); AHB = AttackHitBox; AHB.transform.parent = player.transform; }
private void Awake() { state = State.Idle; startPosition = transform.position; rbody = GetComponent <Rigidbody>(); sound = GetComponent <AudioSource>(); animator = GetComponent <Animator>(); var eventsInvoker = animator.GetBehaviour <AnimationEventsInvoker>(); eventsInvoker.stateEndEvent.AddListener(OnAnimationEnd); squash = GetComponent <SquashEffect>(); attack = GetComponentInChildren <AttackHitBox>(); healthComp = GetComponent <EnemyHealth>(); }
// Use this for initialization override protected void Awake() { base.Awake(); health = 3; state = State.Idle; startPosition = transform.position; rbody = GetComponent <Rigidbody>(); sound = GetComponent <AudioSource>(); animator = GetComponent <Animator>(); var eventsInvoker = animator.GetBehaviour <AnimationEventsInvoker>(); eventsInvoker.stateEndEvent.AddListener(OnAnimationEnd); attack = GetComponentInChildren <AttackHitBox>(); }
private void Awake() { if (instance != null) { Debug.LogError("More than one player exists!"); Destroy(this.gameObject); } instance = this; moveVec = Vector2.right; currentHealth = GetVariable(VariableType.HP); ahb = GetComponentInChildren <AttackHitBox>(); anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody2D>(); //hp = GetComponentInChildren<HPBar>(); anim.SetFloat("SpeedMultiplier", attackSpeed); }