// Start is called before the first frame update void Start() { Game.instance.enemyDirector.RegisterEnemy(this); mEnemyAI = GetComponent <EnemyAI>(); mReveal = GetComponentInChildren <RevealWhenAvatarIsClose>(); commonComponents.killable.onDeath += OnDeath; commonComponents.killable.onHit += OnHit; Game.instance.centralEvents.FireEnemyCreated(this); }
private void DropItems(string prefabName, int num) { List <Vector2Int> emptySurroundingPositions = null; for (int i = 0; i < num; ++i) { GameObject newItem = GameObject.Instantiate(PrefabManager.instance.PrefabByName(prefabName)); Vector3 sourcePosition = transform.position; Vector3 endPosition = transform.position + VectorHelper.RandomNormalizedXZVector3() * Random.Range(0.1f, 0.3f); if (scatter) { if (emptySurroundingPositions == null) { Vector2Int mapCoords = MapCoordinateHelper.WorldToMapCoords(sourcePosition); emptySurroundingPositions = Game.instance.levelGenerator.collisionMap.EmptyOffsetsNearPosition(mapCoords, 1); } Vector2Int offsetMapPos = new Vector2Int(0, 0); if (emptySurroundingPositions.Count > 0) { offsetMapPos = emptySurroundingPositions.Sample(); } Vector3 offsetWorldPos = MapCoordinateHelper.MapToWorldCoords(offsetMapPos, 0f); endPosition += offsetWorldPos; } newItem.transform.position = sourcePosition; RevealWhenAvatarIsClose reveal = newItem.GetComponentInChildren <RevealWhenAvatarIsClose>(); if (reveal != null) { reveal.enabled = false; } Collectable collectable = newItem.GetComponent <Collectable>(); if (collectable != null) { collectable.PlayDropAnimation(sourcePosition, endPosition, i != 0); } } }
private IEnumerator MoveCoroutine(Vector3 direction, Vector3?absoluteTargetPosition = null) { if (mIsMoving && collisionIdentity > 0) { Debug.LogError("Double movement detected"); } mIsMoving = true; Vector3 position = transform.position; Vector3 targetPosition = transform.position + direction; if (absoluteTargetPosition.HasValue) { targetPosition = absoluteTargetPosition.Value; } bool adjustScale = transform.localScale.x > 0.9f; RevealWhenAvatarIsClose revealComp = GetComponent <RevealWhenAvatarIsClose>(); if (revealComp != null) { adjustScale = revealComp.fullyRevealed; } if (useCollisionMap) { UpdateCollisionMapForMove(position, targetPosition); } OrientToDirection(subMesh, direction); float speedMultiplier = 1f; if (mCharacterStatistics != null) { speedMultiplier = 1f + mCharacterStatistics.ModifiedStatValue(CharacterStatType.Speed, gameObject) / 10f; } float time = 0f; while (time < 1f) { transform.position = Vector3.Lerp(position, targetPosition, time); time += Time.deltaTime * 3f * speedMultiplier; float bounceY = (time > 0.5 ? 1f - time : time); bounceY *= bounceY; mesh.transform.localPosition = mMeshLocalPosition + Vector3.up * bounceY; float rotation = (time > 0.5f ? 1 - time : time); rotation *= rotation; float rotationAngle = 60f; mesh.transform.localRotation = Quaternion.Euler(direction.z * rotation * rotationAngle, 0f, -direction.x * rotation * rotationAngle); float squashTime = 0.3f; float stretchTime = 0.75f; float scale = 1f; if (time < squashTime) { scale = 1f - time; } else if (time < stretchTime) { scale = (1f - squashTime) + time * 0.65f; } else { float maxStretch = (1f - squashTime) + stretchTime * 0.75f; scale = maxStretch - (time - stretchTime) * (1 - maxStretch); } if (adjustScale) { transform.localScale = new Vector3(1f, 1f * scale, 1f); } yield return(null); } transform.position = targetPosition; if (adjustScale) { transform.localScale = Vector3.one; } mesh.transform.localRotation = Quaternion.identity; mesh.transform.localPosition = mMeshLocalPosition; mIsMoving = false; if (onMoveFinished != null) { onMoveFinished(); } yield break; }