//called once each tick protected virtual void ForEachTarget(CircleCollider2D coll) { if (coll.gameObject.tag == "Enemy") { Enemy e = coll.GetComponent <Enemy>(); if (e != null) { if (vampIsOn) { if (e.GetHP() < damagePerTick) { dial.ChangeHealth(e.GetHP()); } else { dial.ChangeHealth(damagePerTick); } } e.TakeDamage(damagePerTick); } } else if (coll.gameObject.tag == "EnemyShield") { EnemyShield es = coll.GetComponent <EnemyShield>(); if (es != null) { es.TakeDamage(damagePerTick); } } }
IEnumerator CheckingKick() { kickCollider.GetComponent <SpriteRenderer>().color = Color.red; bool done = false; int t = 0; while (t < kickDurationFrames) { if (!done) { LayerMask mask = LayerMask.GetMask("Boosts"); if (cc.IsTouchingLayers(mask) || kickCollider.IsTouchingLayers(mask)) { AddKickVelocity(); done = true; } else { mask = LayerMask.GetMask("Boosts", "Surfaces"); if (kickCollider.IsTouchingLayers(mask)) { AddKickVelocity(); done = true; } } } yield return(new WaitForFixedUpdate()); t++; } kickCollider.GetComponent <SpriteRenderer>().color = Color.black; }
private void CheckCollisions() { Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, collider.radius); foreach (Collider2D collider in cols) { if (collider.gameObject.CompareTag("Radio")) { audioSource.clip = radioExplosion; if (!hits.Contains(collider.gameObject)) { collider.GetComponent <Radio>().Damage(); hits.Add(collider.gameObject); } } else if (collider.gameObject.CompareTag("MedKit")) { collider.GetComponent <MedKit>().damaged = true; } else if (collider.gameObject.CompareTag("ShieldGen")) { collider.GetComponent <ShieldGenerator>().Damage(); } else if (collider.gameObject.CompareTag("Player")) { if (!hits.Contains(collider.gameObject)) { collider.GetComponent <Player>().removeHealth(1); hits.Add(collider.gameObject); } } } }
private void OnDestroy() { Debug.Log("Destroy"); Destroy(drawer); Destroy(circleCol.GetComponent <CircleCollider2D>()); Destroy(circleCol); }
void GetLengthToScoreMiddle() { bool isCollidng = myCollider.IsTouching(scoreCollider); if (isCollidng == false) { return; } Debug.Log(isCollidng); Vector2 scoreCenter = scoreCollider.GetComponent <RectTransform>().anchoredPosition; Vector2 mineCenter = GetComponent <RectTransform>().anchoredPosition; Debug.DrawLine(scoreCenter, mineCenter); float length = (scoreCenter - mineCenter).magnitude; float combineRadius = Mathf.Abs(myCollider.radius + scoreCollider.radius); //Debug.Log("Length: " + length + " Radius: " + combineRadius); /*if (length > combineRadius) * { * return; * }*/ Debug.Log("Length: " + length + " combineRadius: " + combineRadius); int scoreAmount = (int)((1 - (length / (scoreCollider.radius * 2))) * 100); Debug.Log(scoreAmount); }
// Start is called before the first frame update private void Start() { gameObject.tag = "LaserCollider"; gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); laserColl = laserColl.GetComponent <CircleCollider2D>(); laserColl.isTrigger = true; }
// Método para comprobar si el jugador colisiona con la llama. private void comprobarMuertePersonaje() { if (jugador.IsTouching(GetComponent <CircleCollider2D>())) { jugador.GetComponent <PlayerController>().setDanyo(danyo); } }
public void MakeDynamic() { dynamic = true; if (!spriteRenderer) { spriteRenderer = GetComponent <SpriteRenderer>(); } spriteRenderer.sprite = Graphics.instance.dynamicObjectiveSprite; Destroy(GetComponent <Collider2D>()); CircleCollider2D newCollider = gameObject.AddComponent <CircleCollider2D>(); // newCollider.radius = 1; newCollider.isTrigger = true; if (!dynamicGraphCollider) { dynamicGraphCollider = GetComponentInChildren <CircleCollider2D>(); } dynamicGraphCollider.GetComponent <Collider2D>().enabled = true; }
protected override void Attack() { // This will be the Laser Beam code // Need A laser beam line Renderer to draw to max range with a box collider on it that damages enemies inside of it all the time if (IsPlayerInSight()) { laserChargeTimer += Time.deltaTime; if (laserChargeTimer > LaserChargeTime) { laserFiringTimer += Time.deltaTime; LaserBeamHolder.SetActive(true); if (laserFiringTimer > laserFiringMaxTime) { laserChargeTimer = 0; laserFiringTimer = 0; LaserBeamHolder.SetActive(false); } } } // This is the EMPWave Code; EMPWaveTimer += Time.deltaTime; if (EMPWaveTimer > TimeBetweenEMPWaves) { OuterRing.gameObject.SetActive(true); EMPWaveGrowthTimer += Time.deltaTime; OuterRing.gameObject.DrawCircle(EMPWaveBaseRadius + EMPWaveGrowthTimer * EMPWaveGrowthRate, 2, 0.25f, lightningMat); OuterRing.radius = EMPWaveBaseRadius + EMPWaveGrowthTimer * EMPWaveGrowthRate; LineRenderer lr = OuterRing.GetComponent <LineRenderer>(); lr.alignment = LineAlignment.TransformZ; lr.receiveShadows = false; if (EMPWaveGrowthTimer > EMPWaveGrowthMaxTime) { EMPWaveTimer = 0; EMPWaveGrowthTimer = 0; OuterRing.gameObject.SetActive(false); Destroy(OuterRing.GetComponent <LineRenderer>()); } } SpawnMinions(); }
// Privates private void MoveBall() { paddleBuffer.GetComponent <CircleCollider2D>().enabled = true; currentBall.GetComponent <SpriteRenderer>().enabled = false; currentBall.transform.localScale = new Vector3(1, 1, 1); currentBall.transform.position = RandomCirclePos(); Collider2D[] colliders = Physics2D.OverlapCircleAll(paddle.transform.position, paddleBuffer.radius); foreach (Collider2D collider in colliders) { if (collider.gameObject.tag == "Ball") { //Debug.LogWarning("Moved ball inside buffer, vector: " + collider.gameObject.transform.position); MoveBall(); return; } } currentBall.GetComponent <SpriteRenderer>().enabled = true; paddleBuffer.GetComponent <CircleCollider2D>().enabled = false; }
// Start is called before the first frame update void Start() { rb2d = GetComponent <Rigidbody2D>(); enemyAggro = aggroCollider.GetComponent <EnemyAggro>(); rightChecker = sideCheckerRight.GetComponent <SideCheckerRight>(); leftChecker = sideCheckerLeft.GetComponent <SideCheckerLeft>(); groundChecker = groundCheckBox.GetComponent <GroundChecker>(); avoidPlayerChecker = avoidPlayerCapsule.GetComponent <EnemyAvoidPlayerBlock>(); thisEnemy = enemy.GetComponent <Enemy>(); enemyRange = attackPoint.GetComponent <EnemyRangeCheck>(); }
void Eat(CircleCollider2D food) { if (food != null) { //Debug.Log("Eat food=" + food.radius); var iAdd = food.GetComponent <IAddStrongBody>(); if (iAdd != null) { if (iAdd.IsAddStrongBody()) { _Character.AddBody(true); } } var iScore = food.GetComponent <IScore>(); if (iScore != null) { _Character.AddScore(iScore.GetScore(), !iAdd.IsAddStrongBody()); } } }
private void OnTriggerStay2D(Collider2D collision) { CircleCollider2D circleCollider = collision.GetComponent<CircleCollider2D>(); float playerZ = circleCollider.transform.position.y; float playerRadius = circleCollider.radius; float submergeRatio = (surfaceLevel - (playerZ - playerRadius)) / (playerRadius * 2); SubmergePhysics submergePhysic = circleCollider.GetComponent<SubmergePhysics>(); submergePhysic.submergeAmount(submergeRatio); }
protected override void ForEachTarget(CircleCollider2D coll) { if (coll.gameObject.tag == "Enemy") { //Debug.Log("Here's an enemy in ShieldTrapField"); Enemy e = coll.GetComponent <Enemy>(); if (e != null) { //Drain if (drainPerTick > 0f) { //Debug.Log("doing drain in ShieldTrapField"); if (e.GetHP() < drainPerTick) { dial.ChangeHealth(e.GetHP()); //multiplier applied in SetUp() } else { dial.ChangeHealth(drainPerTick); //multiplier applied in SetUp() } e.TakeDamage(drainPerTick); } if (coolPerTick > 0f) { ReduceCooldown(coolPerTick); //multiplier applied in SetUp() } } } else if (coll.gameObject.tag == "EnemyShield") { EnemyShield es = coll.GetComponent <EnemyShield>(); if (es != null) { //es.TakeDamage(damagePerTick); //Drain if (drainPerTick > 0f) { } } } }
public override void TraverseBVHForCircle(CircleCollider2D cc, out int searchCount) { this.targetRb2D = cc.GetComponent <Rigidbody2D>(); this.cc = cc; this.searchCount = 0; if (targetRb2D && this.cc) { this.targetPos = transform.InverseTransformPoint(cc.transform.position); TraverseBinaryTreeForCircle(this.branch); } searchCount = this.searchCount; }
void OnTriggerEnter2D(Collider2D collision) { Debug.Log("Reset"); CircleCollider2D ball = collision.GetComponent <CircleCollider2D>(); if (ball != null) { if (ball.gameObject.CompareTag("Ball")) { ball.GetComponent <Ball>().ResetBall(); gm.LoseLife(); } } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer <= 0) { radius.GetComponent <CircleCollider2D>().enabled = true; pickupSpoof.Play(true); } if (timer <= -1) { Destroy(gameObject); } }
public void Initalize(GameManager gm) { this.gameManager = gm; col.OnTriggerEnter2DAsObservable() .Where(c => c.GetComponent <Candle>() != null) .Select(c => c.GetComponent <Candle>()) .Do(c => c.SwitchIcon(true)) .Subscribe(c => targetCandle = c); col.OnTriggerExit2DAsObservable() .Where(col => col.GetComponent <Candle>() != null) .Do(c => c.GetComponent <Candle>().SwitchIcon(false)) .Subscribe(_ => targetCandle = null); gameManager.InputProvider.OnHorizontal .Select(h => (litCandle?.IsStop.Value ?? true && (!litCandle?.IsAlive.Value ?? false)) ? 0 : h) .Select(h => gameManager.OnGameState.Value == GameState.GameOver ? 0 : h) .Subscribe(h => rb.velocity = new Vector2(h * speedV, rb.velocity.y)); gameManager.InputProvider.OnVertical .Select(v => (litCandle?.IsStop.Value ?? true && (!litCandle?.IsAlive.Value ?? false)) ? 0 : v) .Select(h => gameManager.OnGameState.Value == GameState.GameOver ? 0 : h) .Subscribe(v => rb.velocity = new Vector2(rb.velocity.x, v * speedV)); var fire = gameManager.InputProvider.OnFire .Where(_ => targetCandle != null) .Share(); fire.Subscribe(_ => BonfireLit()).AddTo(gameObject); fire .DelayFrame(10).First() .Subscribe(start => { gameManager.ChangeState(GameState.InGame); }); gameManager.OnGameState .Where(x => x == GameState.GameOver) .First() .Subscribe(_ => { litCandle.transform.SetParent(gameManager.candleProvider.transform); transform.DOScale(Vector3.zero, 3); rb.velocity = Vector2.zero; }); _initialized.OnNext(Unit.Default); }
// Use this for initialization void Start() { //Debug.Log(GetComponentInParent<Vision>()); if (transform.parent == null || transform.parent.GetComponent <Vision>() == null) { initiate = true; visionZone = new GameObject().AddComponent <CircleCollider2D>(); visionZone.transform.parent = transform; visionZone.transform.localPosition = Vector3.zero; visionZone.gameObject.AddComponent <Vision>().radius = radius; visionZone.gameObject.AddComponent <Rigidbody2D>(); visionZone.GetComponent <Rigidbody2D>().simulated = false; visionZone.offset = new Vector2(0, 0); visionZone.radius = (radius - 5) / 100; //Debug.Log(LayerMask.NameToLayer("FogOfWar")); visionZone.gameObject.layer = LayerMask.NameToLayer("FogOfWar"); } }
private void OnTriggerExit2D(Collider2D collision) { CircleCollider2D circleCollider = collision.GetComponent<CircleCollider2D>(); float playerZ = circleCollider.transform.position.y; SubmergePhysics submergePhysic = circleCollider.GetComponent<SubmergePhysics>(); // Fully on land if (playerZ > surfaceLevel) { submergePhysic.submergeAmount(0.0f); } // Fully in water else { submergePhysic.submergeAmount(1.0f); } }
// Create line from two point public void Create(Vector3 start, Vector3 end, int index, bool autoScale = true) { this.Init(); lineRender.SetPosition(0, start); lineRender.SetPosition(1, end); this.index = index; DetectDirection(); //corner.radius = lineRender.startWidth; corner.transform.localPosition = start; corner.GetComponent <SpriteRenderer>().color = lineRender.startColor; if (autoScale) { ScaleCollider(); } }
void RPC_Push() { AudioFW.Play("Boom"); Instantiate(PushEffect, transform.position, Quaternion.identity); Debug.Log("Push"); if (PhotonNetwork.isMasterClient) { Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, specialEffectArea * 0.5f, layerMaskEnemy); foreach (Collider2D col in hits) { if (col.GetComponent <EnemyCharacter>()) { if (!col.GetComponent <EnemyCharacter>().stunned&& !col.GetComponent <EnemyCharacter>().flying) { Rigidbody2D enemyRB = col.GetComponent <Rigidbody2D>(); Vector3 enemyLoc = col.GetComponent <Transform>().position; Vector2 pushVector = new Vector2(enemyLoc.x - transform.position.x, enemyLoc.y - transform.position.y).normalized; col.GetComponent <EnemyCharacter>().Fly(0.5f); //enemyRB.AddForce(pushVector * pushForce, ForceMode2D.Impulse); } } } } }
private int NumberOfPlayerIntheRay(Color team) { return(playerNextToRay.GetComponent <PlayerCounter>().GetPlayerCounter(team)); }
void Start() { TowerRange = TowerRange.GetComponent <CircleCollider2D>(); nextFire = Time.time; }
new void Start() { base.Start(); BlastRadius.GetComponent <CircleCollider2D>().enabled = false; }
private void OnEnable() { _circleCollider.GetComponent <CircleCollider2D>(); StartCoroutine(SplashDelay()); }
void CheckHit() { if (!hasHit) { Collider2D[] collider2Ds = new Collider2D[200]; Physics2D.OverlapCollider(collider, contactFilter, collider2Ds); foreach (Collider2D collider in collider2Ds) { if (collider != null) { Enemy enemyHit = collider.GetComponent <Enemy>(); Boss bossHit = collider.GetComponent <Boss>(); ChestAndBox chestAndBoxHit = collider.GetComponent <ChestAndBox>(); // Enemy Hit if (enemyHit != null) { Vector2 enemyPos = enemyHit.transform.position; Vector2 vector = enemyPos - (Vector2)transform.position; Vector2 dir = vector.normalized; float dist = vector.magnitude; RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position, dir, dist, LayerMask.NameToLayer("mapColliders")); if (!hit) { int damages = Mathf.CeilToInt(baseDamages * player.stats.capacitiesDamagesM); // FeedBacks enemyHit.TakeDamage(damages); hasHit = true; currentLifeTime = 0; } } // BOSS HIT CHECK if (bossHit != null) { Vector2 playerCenter = (Vector2)player.centerTransform.position; Vector2 bossPos = bossHit.transform.position; Vector2 vector = bossPos - playerCenter; Vector2 dir = vector.normalized; float dist = vector.magnitude; RaycastHit2D hit = Physics2D.Raycast(player.centerTransform.position, dir, dist, LayerMask.NameToLayer("mapColliders")); if (!hit) { int damages = Mathf.CeilToInt(baseDamages * player.stats.capacitiesDamagesM); // FeedBacks bossHit.TakeDamage(damages); hasHit = true; currentLifeTime = 0; } } // CHEST HIT CHECK if (chestAndBoxHit != null) { chestAndBoxHit.Hit(); hasHit = true; currentLifeTime = 0; } } } } }