void LateUpdate() { if (transform.parent.localScale.x > maxRadius) { Destroy(gameObject); } Collider2D[] hitCols = Physics2D.OverlapCircleAll((Vector2)transform.position + col.offset, col.radius * transform.lossyScale.x, ~(1 << 0)); foreach (Collider2D hitCol in hitCols) { //check if platform is interactable with this ability DynamicPlatformController platform = hitCol.GetComponent <DynamicPlatformController>(); if (platform == null) { continue; } bool isInteractable = false; isInteractable = emotion == Emotion.Anger && (platform._type == "Shove" || platform._type == "Universal") ? true : isInteractable; isInteractable = emotion == Emotion.Joy && (platform._type == "Float" || platform._type == "Universal") ? true : isInteractable; isInteractable = emotion == Emotion.Sadness && platform._affectedBySlow ? true : isInteractable; //apply effect if (!hitColliders.Contains(hitCol) && isInteractable) { hitColliders.Add(hitCol); Vector3 point = hitCol.ClosestPoint(transform.position); GameObject effect = Instantiate(effectPrefab, point, Quaternion.identity, hitCol.transform); effect.GetComponent <CollisionEffect>().emotion = emotion; effect.transform.up = (transform.position - point).normalized; } } if (transform.parent.localScale.x == maxRadius) { Destroy(gameObject); } }
private void Start() { pXPos = transform.position.x; dynamicScript = GetComponent <DynamicPlatformController>(); }
private void OnValidate() { animator = GetComponent <Animator>(); platformController = GetComponent <DynamicPlatformController>(); }
void OnCollisionStay2D(Collision2D coll) { // Case when PJ is on a platform if (coll.gameObject.tag == "DynamicPlatform" && platform == null) { platform = coll.gameObject.GetComponent<DynamicPlatformController> (); } if (platform != null) { transform.Translate(Vector3.right * rotation * platform.horizontalSpeed * platform.horizontalDirection * Time.deltaTime); transform.Translate(Vector3.up * rotation * platform.verticalSpeed * platform.verticalDirection * Time.deltaTime); } }
void OnCollisionExit2D(Collision2D coll) { // Case when PJ is on a platform if (coll.gameObject.tag == "DynamicPlatform") { platform = null; } }