void KamiKaze() { if (!SuicidePathSet) //start to use the suicide path if it hasn't been set yet { WaypointIndex = 0; foreach (Transform wayPoint in DeadlyWayPointMap) { var PointPosition = wayPoint.position; float SuicideLateralOffset = EnemySettings.GetSuicideLateralOffset(); Vector3 LateralOffset = new Vector3(Random.Range(-SuicideLateralOffset, SuicideLateralOffset), PointPosition.y, PointPosition.z); wayPoint.position = LateralOffset; } //randomize the waypoint positions for the kamikaze route SuicidePathSet = true; //path has ben set } if (WaypointIndex < DeadlyWayPointMap.Count)//current i < # of items in list { var targetPosition = DeadlyWayPointMap[WaypointIndex].transform.position; var MovementThisFrame = EnemySettings.GetMoveSpeed() * EnemySettings.GetSuicideSpeedMultiplier() * Time.deltaTime; //really just speed transform.position = Vector3.MoveTowards(transform.position, targetPosition, MovementThisFrame); //movetowards(startingpoint,destination,speed) //when reached, use next Waypoint if (transform.position == targetPosition) { WaypointIndex++; } } else { FindObjectOfType <PH_GameSession>().AddToScore(-EnemyData.GetPoints()); EnemyData.Die(); } //destroy the object when it reaches the last waypoint an a loop is not setup } //substract points so that the score doesn't go up from enemy selfdestruct
public void Hit() { PH_Enemy EnemyScript = gameObject.GetComponent <PH_Enemy>();//check if the object has an enemy script if (!EnemyScript) { Destroy(gameObject); } //if it doesn't, just destroy it normally on contact else { EnemyScript.Die(); } //if it is an enemy, use it's 'Die' function. }