protected bool CheckGroundCollision() { bool ret = false; RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, 0.3f, transform.up * -1, _rayCastGroundRange, groundMask.value); foreach (RaycastHit2D hit in hits) { if (hit.transform != null) { if (hit.distance <= 1) { Platform p = hit.transform.GetComponent <Platform>(); if (p != null) { if (transform.position.y - halfHeight + 0.15f >= p.transform.position.y + p.platformHeight / 2) { if (p.CompareTag(Constants.TAG_SAFETY_NET)) { BurstJump(safetyNetJump); p.gameObject.SetActive(false); return(false); } ret = true; DestroyablePlatform dp = hit.transform.gameObject.GetComponent <DestroyablePlatform>(); if (dp != null) { dp.StartFalling(); } } } else { Enemy e = hit.transform.GetComponent <Enemy>(); if (e != null && e._hitsLeft > 0) { if (transform.position.y - halfHeight + 0.5f >= e.transform.position.y + e.spriteHeight / 2) { e.Hit(); ret = true; } } } } } } return(ret); }
public void FixedUpdate() { if (state == PlatformState.Active) { if (_addPlatformComponent) { if (_platformToAdd == PlatformTypeChance.PlatformType.Destroyable) { DestroyablePlatform dp = GetComponent <DestroyablePlatform>(); if (dp == null) { gameObject.AddComponent <DestroyablePlatform>(); } } else if (_platformToAdd == PlatformTypeChance.PlatformType.MovingPlatform) { MovingPlatform mp = GetComponent <MovingPlatform>(); if (mp == null) { gameObject.AddComponent <MovingPlatform>(); } } } if (_runScaleAnimation) { Vector3 newScale = transform.localScale; newScale.x = _resizeTo; transform.localScale = Vector3.Lerp(transform.localScale, newScale, Time.deltaTime * scaleAnimationTime); platformWidth = newScale.x; if (Mathf.Abs(transform.localScale.x - newScale.x) <= 0.2f) { _runScaleAnimation = false; } } if (levelGenerator) { if (Mathf.Abs(transform.position.y - Camera.main.transform.position.y) >= levelGenerator.platfromDestroyDistance) { levelGenerator.DestroyObject(gameObject); } } } }
public void Reset() { SetKinematic(true); _addPlatformComponent = false; _runScaleAnimation = false; MovingPlatform mp = gameObject.GetComponent <MovingPlatform>(); if (mp != null) { Destroy(mp); } DestroyablePlatform dp = gameObject.GetComponent <DestroyablePlatform>(); if (dp != null) { Destroy(dp); } state = PlatformState.Idle; prevState = PlatformState.Idle; }