void DestroyGameObject() { SpriteRenderer sprite = null; if (!playDeathSound) { AudioSource.PlayClipAtPoint(DeathSound, transform.position); playDeathSound = !playDeathSound; } foreach (Transform childObj in transform) { if (childObj.name == "animation") { sprite = childObj.gameObject.GetComponent <SpriteRenderer>(); if (sprite != null) { var animator = GetAnimator(); if (animator == null) { return; } animator.Play("Fall"); Destroy(this.gameObject, animDie.length); } } } IpiCounter.Minus(); }
void OnTriggerStay(Collider other) { if (activateBehaviour && !destoryObject && go) { if (IsSamePosition(other.transform.position)) { var draggable = other.GetComponent <ChangeDirection> (); if (draggable != null) { //Hetkel kui on sama värvi, siis pöörab sinna kuhu on määratud //Kui on teist värvi, siis läheb läbi if (IsCorrectGate(draggable)) { transform.position = new Vector3(other.transform.position.x, other.transform.position.y, transform.position.z); Rotate(draggable._vectorDirection, draggable.currentDirection); activateBehaviour = false; } } //Kui on tegemist topel väravaga, siis pole mõtet kontrollida materiali var doubleDraggable = other.GetComponent <ChangeDirectionDouble>(); if (doubleDraggable != null) { transform.position = new Vector3(other.transform.position.x, other.transform.position.y, transform.position.z); Rotate(doubleDraggable.GetVectorDirection(Color), doubleDraggable.GetDirectionEnum(Color)); activateBehaviour = false; } var jump = other.GetComponent <Jump>(); if (jump != null && (IsCorrectGate(jump) || jump.IsNeutral)) { animationEndPosition = jump.GetNewPosition(this.CurrentDirection, transform.position); Jump(CurrentDirection); activateBehaviour = false; isJumping = true; } var size = other.GetComponent <SizeGate>(); if (size != null) { this.Size = size.ToSize; Play(); } var changeColorGate = other.GetComponent <ChangeColorGate>(); if (changeColorGate != null) { activateBehaviour = false; changeColorGate.DoColorChange(this); //Play(); } var changeDirectionStatic = other.GetComponent <StaticChangeDirection> (); if (changeDirectionStatic != null && (IsCorrectGate(changeDirectionStatic) || changeDirectionStatic.IsNeutral)) { transform.position = new Vector3(other.transform.position.x, other.transform.position.y, transform.position.z); Rotate(changeDirectionStatic.GetVectorDirection(), changeDirectionStatic.currentDirection); activateBehaviour = false; } var teleportGate = other.GetComponent <Teleport> (); if (teleportGate != null) { activateBehaviour = false; var teleportGates = GameObject.FindGameObjectsWithTag("Teleport"); foreach (var tG in teleportGates) { var tGate = tG.transform.GetComponent <Teleport> (); if (tGate == null) { continue; } if (teleportGate.groupName == tGate.groupName && teleportGate.PublicInstanceID != tGate.PublicInstanceID) { TelePortExtiGateInstanceID = tGate.PublicInstanceID; activateBehaviour = false; AudioSource.PlayClipAtPoint(TeleportSound, transform.position); transform.position = new Vector3(tGate.transform.position.x, tGate.transform.position.y, transform.position.z); break; } } } var finish = other.GetComponent <FinishCounter>(); if (finish != null) { if (finish.IsCorrectObject(this.GetComponent <Collider>())) { var animator = GetAnimator(); if (animator == null) { return; } go = false; animator.Play("Finish"); //tekitab finishi particle GameObject finishParticle = Instantiate(Resources.Load("prefabs/finishParticle", typeof(GameObject)), new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z - 2), Quaternion.identity) as GameObject; Destroy(this.gameObject, animFinish.length); IpiCounter.Minus(); MainMenu mainMenu = GameMaster.GetMainMenu(); mainMenu.SetMinusOne(); } } var colorWall = other.GetComponent <ColorWall> (); if (colorWall != null && IsCorrectGate(colorWall)) { TurnAround(); activateBehaviour = false; } } var destroy = other.GetComponent <Destroy> (); if (destroy != null) { destoryObject = tag != "Template"; } var gun = other.GetComponent <Gun>(); if (gun != null) { destoryObject = destroyOnGun && tag != "Template"; } } }