public virtual T CollisionDetect <T>(Vector2 end, MovingObject owner) where T : Component { T other; RaycastHit2D hit; boxCollider.enabled = false; if (owner.GetComponent <BoxCollider2D>()) { owner.GetComponent <BoxCollider2D>().enabled = false; } hit = Physics2D.Linecast(logicalPos + end, logicalPos + end, ThrowBlockingLayer); boxCollider.enabled = true; if (owner.GetComponent <BoxCollider2D>()) { owner.GetComponent <BoxCollider2D>().enabled = true; } if (hit.transform) { other = hit.transform.GetComponent <T>(); if (other) { return(other); } } return(null); }
private void Surface() { floatingObj.GetComponent <SpriteRenderer>().enabled = true; floatingObj.GetComponent <Collider2D>().enabled = true; floatingObj.tag = floatingItemTag; underwater = false; }
private void SpawnBoss() { MovingObject boss = PoolManager.Instance.GetPooledObject(BossNames[bossCount]); boss.transform.position = BossPosition; boss.GetComponent <Boss>().MySpawner = this; boss.GetComponent <Boss>().PlayerTransform = PlayerTransform; boss.gameObject.SetActive(true); }
private void CreatePlanet() { MovingObject p = PoolManager.Instance.GetPooledObject("planet"); p.transform.position = new Vector3(Random.Range(-gameWidth / 2, gameWidth / 2), 3); float scale = Random.Range(0.2f, 0.4f); p.transform.localScale = new Vector2(scale, scale); p.GetComponent <SpriteRenderer>().sprite = Planets[Random.Range(0, Planets.Length)]; p.GetComponent <ScrollingObject>().Direction = new Vector2(0, Random.Range(-1f, -0.6f)); p.gameObject.SetActive(true); }
public void TouchedWater(MovingObject movingObject) { if (_gameManager == null) { _gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); } if (!_gameManager.GamePlaying()) { // Nothing should move return; } // Detect if this object floats if (movingObject.CanFloat) { if (movingObject.gameObject.tag == "Platform") { _currentPlatform = movingObject.gameObject; } Move(movingObject); } else { movingObject.GetComponent <BoxCollider>().enabled = false; movingObject.FellInWater(); movingObject.Respawn(); } }
public void SpawnRocket(Vector3 pos) { MovingObject rocket = PoolManager.Instance.GetPooledObject("rocket"); rocket.transform.position = pos; rocket.gameObject.SetActive(true); rocket.GetComponent <Rocket>().SetNewRocket(); }
private void SpawnUpgrade() { MovingObject item = PoolManager.Instance.GetPooledObject("weaponUpgrade"); item.GetComponent <WeaponUpgrade>().WeaponStat = BossLoot; item.transform.position = transform.position; item.gameObject.SetActive(true); }
public IEnumerator UseEffect(MovingObject owner) { isWaitAnimation = true; MessageWindow.instance.ConOut(owner.Status.Name + "は" + Profile.Name + "を使った!\n"); yield return(new WaitForSeconds(0.5f)); if (Profile.UseEffectTypeValue == ItemProfile.ItemType.NoEffect) { MessageWindow.instance.ConOut("しかし何も起きなかった…\n"); Node.UsableTime--; } if (Profile.UseEffectTypeValue == ItemProfile.ItemType.RecoverLife) { MessageWindow.instance.ConOut("HPが" + Profile.EffectValue + "回復した!\n"); owner.RecoverLife(Profile.EffectValue); Node.UsableTime--; } if (Profile.UseEffectTypeValue == ItemProfile.ItemType.GainFood) { MessageWindow.instance.ConOut("お腹が膨れた!\n"); Node.UsableTime--; } if (Profile.UseEffectTypeValue == ItemProfile.ItemType.CastMagic) { owner.UseMagic = Profile.MagicID; StartCoroutine(owner.CastMagic <MovingObject>()); do { yield return(null); } while (owner.waitAttackingProcess); Node.UsableTime--; } if (owner.GetComponent <Player>()) { owner.GetComponent <Player>().GainFood(Profile.GainFoodValue); } yield return(new WaitForSeconds(0.5f)); isWaitAnimation = false; }
public void SpawnEnemies() { for (int i = 0; i < 5; i++) { MovingObject enemy = PoolManager.Instance.GetPooledObject("enemy"); enemy.transform.position = new Vector2(-gameWidth / 2 + i * gameWidth / 4, 2); enemy.gameObject.SetActive(true); SetEnemiesValues(enemy.GetComponent <Enemy>()); } }
public void Shoot(WeaponStats ws) { int count = Mathf.Clamp(ws.BulletAmount, 0, Muzzles.Count); for (int i = 0; i < count; i++) { MovingObject bullet = PoolManager.Instance.GetPooledObject("bullet"); bullet.transform.position = Muzzles[i].position; bullet.transform.rotation = Muzzles[i].rotation; bullet.GetComponent <Bullet>().SetBulletValues(ws); } }
// Start is called before the first frame update void Start() { if (isItStart) { railRoad = new List <GameObject>(); MakeRail(); if (directionType == Direction.x) { if (endPoint.transform.position.x > transform.position.x) { direction = Vector3.right; } else { direction = Vector3.left; } } else { if (endPoint.transform.position.y > transform.position.y) { direction = Vector3.up; } else { direction = Vector3.down; } } this.startPoint = this; if (directionType == Direction.x) { accel = new Vector2(velocity * velocity / (2 * (endPoint.transform.position.x - transform.position.x)), 0f); extraAccel = new Vector2(extraVelocity / (2 * (endPoint.transform.position.x - transform.position.x) / velocity), 0f); } else { accel = new Vector2(0f, velocity * velocity / (2 * (endPoint.transform.position.y - transform.position.y))); extraAccel = new Vector2(0f, extraVelocity / (2 * (endPoint.transform.position.y - transform.position.y) / velocity)); } movingObject = Instantiate(movingObjectPrefab, transform.position, Quaternion.identity); movingObject.transform.localScale *= size; movingObject.mildPlatformTime = this.mildPlatformTime; rb2D = movingObject.GetComponent <Rigidbody2D>(); destin = endPoint; SetRailSpeed(0f); } }
IEnumerator WaitCoroutineUpDown(float time, float x, float y, int dir, bool down) { Debug.Log("about to yield return WaitForSeconds(" + time + ") " + down); yield return(new WaitForSeconds(time)); Debug.Log("Animation ended " + down); ChangePositionDefault(x, y, dir); if (down) { playerAction = Actions.DEFAULT; auxOnObject.GetComponent <Collider2D>().enabled = true; colliderPlayer.enabled = true; } else { playerAction = Actions.ON_OBJECT; } yield break; //Debug.Log("You'll never see this"); // produces a dead code warning }