public virtual GameObject OnSpawn() { var obj = AdvancedGameObjectPooler.GetAvailableObject(spawnerSettings[loopSettings.index].prefab); if (obj) { if (spawnerSettings[loopSettings.index].trackProgress) { var spawnerProgress = obj.GetComponent <ProgressCounter>(); if (spawnerProgress == null) { spawnerProgress = obj.AddComponent <ProgressCounter>(); } //spawnerProgress.hideFlags= HideFlags.HideInInspector; } SetPosition(obj); obj.SetActive(true); spawnerSettings[loopSettings.index].layerSettings.OrderInLayer(obj); counter += 1; } return(obj); }
void _Random(CollisionData collisionData) { var i = Random.Range(0, prefab.Length); var o = AdvancedGameObjectPooler.GetAvailableObject(prefab[i]); o.transform.position = collisionData.transform.position; o.SetActive(true); }
void _AllAtOnce(CollisionData collisionData) { for (int i = 0; i < prefab.Length; i++) { if (prefab[i]) { var o = AdvancedGameObjectPooler.GetAvailableObject(prefab[i]); o.transform.position = collisionData.transform.position; o.SetActive(true); } } }
void _Fire() { _timer -= 1 * Time.deltaTime; if (_timer > 0) { return; } _timer = Random.Range(.25f, .75f); if (frame == 0 || frame == frames.Length - 1) { if (bulletSettings.prefab) { var obj = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.SetActive(true); var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { var direction = -1; var position = bulletSettings.position; if (frame == frames.Length - 1) { direction = -direction; } position.x *= -direction; bulletBase.velocity = new Vector3(bulletSettings.speed + Random.Range(0, 5), 0, 0) * direction; bulletBase.transform.position += position; if (direction == -1) { bulletBase.transform.rotation *= Quaternion.Euler(0, 180, 0); } var spark = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.effectPrefab); spark.transform.position = bulletBase.transform.position; spark.transform.SetParent(transform, true); spark.SetActive(true); } } } } }
public GameObject OnSpawn() { var obj = AdvancedGameObjectPooler.GetAvailableObject(spawnerSettings[loopSettings.index].prefab); if (obj) { _SetPosition(obj, Random.Range(0, 2)); obj.SetActive(true); spawnerSettings[loopSettings.index].layerSettings.OrderInLayer(obj); counter += 1; } return(obj); }
void _Fire() { var frame = additionalSettings.animator.GetCurrentAnimatorClipInfo(0)[0].clip.length * (additionalSettings.animator.GetCurrentAnimatorStateInfo(0).normalizedTime % 1) * additionalSettings.animator.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate; if (_state == 0 && (int)frame == fireFrame) { if (bulletSettings.prefab) { var obj = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.transform.localScale *= bulletSettings.scale; var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { bulletBase.transform.Translate(bulletSettings.position, Space.Self); bulletBase.transform.eulerAngles = new Vector3(0, 0, bulletSettings.rotation); bulletBase.velocity = obj.transform.rotation * new Vector3(bulletSettings.speed, 0, 0); } obj.SetActive(true); } } if (bulletSettings.effectPrefab) { var obj = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.effectPrefab); obj.transform.SetParent(transform, false); obj.transform.Translate(bulletSettings.position, Space.Self); obj.transform.localScale *= bulletSettings.scale; obj.SetActive(true); } _state = 1; } else if (_state == 1 && (int)frame != fireFrame) { _state = 0; } }
void _Shrapnel() { for (int i = 0; i < shrapnelProperties.parts; i++) { var obj = AdvancedGameObjectPooler.GetAvailableObject(shrapnelProperties.prefab); if (obj) { var bullet = obj.GetComponent <BulletBase>(); if (bullet) { obj.transform.position = transform.position; float angle = i * (360f / shrapnelProperties.parts) * Mathf.Deg2Rad; obj.transform.eulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg); bullet.velocity = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * shrapnelProperties.speed; } obj.SetActive(true); } } }
public void Update(Vector3 position, GameObject target) { glow.transform.position = position; timer -= 1 * Time.deltaTime; if (timer > 0) { return; } timer = interval; var obj = AdvancedGameObjectPooler.GetAvailableObject(prefab); if (obj == null) { return; } var bullet = obj.GetComponent <BulletBase>(); if (bullet == null) { return; } obj.transform.position = position; obj.SetActive(true); var angle = Mathf.Atan2(target.transform.position.y - position.y, target.transform.position.x - position.x); bullet.velocity = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * speed; glow.color = glowColor; glow.enabled = true; }
public virtual GameObject OnSpawn() { if (mode == Mode.TargetPlayer) { var target = PlayersGroup.GetAny(); if (target) { var obj = AdvancedGameObjectPooler.GetAvailableObject(prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.transform.Translate(position, Space.Self); layerSettings.OrderInLayer(obj); obj.SetActive(true); var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { var angle = Mathf.Atan2(target.transform.position.y - obj.transform.position.y, target.transform.position.x - obj.transform.position.x); obj.transform.eulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg); bulletBase.velocity = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * _RandomFloat(speed); } } return(obj); } } else if (mode == Mode.TargetEnemy) { var target = Targetable.GetClosest(gameObject, targetEnemySettings.targetRange); if (target) { var obj = AdvancedGameObjectPooler.GetAvailableObject(prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.transform.Translate(position, Space.Self); layerSettings.OrderInLayer(obj); obj.SetActive(true); var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { var angle = Mathf.Atan2(target.transform.position.y - obj.transform.position.y, target.transform.position.x - obj.transform.position.x); obj.transform.eulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg); bulletBase.velocity = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * _RandomFloat(speed); } } return(obj); } } else if (mode == Mode.Random) { var obj = AdvancedGameObjectPooler.GetAvailableObject(prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation; obj.transform.Translate(position, Space.Self); layerSettings.OrderInLayer(obj); obj.SetActive(true); var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { var angle = Random.Range(0, 359) * Mathf.Deg2Rad; obj.transform.eulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg); bulletBase.velocity = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * _RandomFloat(speed); } } return(obj); } else if (mode == Mode.Direction) { if (directionSettings.smartSpawn == true && ObjectCounter.counter > 0 || directionSettings.smartSpawn == false) { var obj = AdvancedGameObjectPooler.GetAvailableObject(prefab); if (obj) { obj.transform.position = transform.position; obj.transform.rotation = transform.rotation * Quaternion.Euler(directionSettings.rotation); obj.transform.Translate(position, Space.Self); layerSettings.OrderInLayer(obj); obj.SetActive(true); var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { bulletBase.velocity = obj.transform.rotation * new Vector3(_RandomFloat(speed), 0, 0); } } return(obj); } } return(null); }
void _Update() { var fire = -1; _timer += 1 * Time.deltaTime; if (_timer > .1) { fire = Random.Range(0, guns.Length); _timer = 0; } for (int i = 0; i < guns.Length; i++) { if (guns[i] == null) { continue; } var angle = i * Mathf.PI * 2f / guns.Length; angle += rotation; guns[i].transform.localPosition = new Vector3(Mathf.Cos(angle) * radius, -Mathf.Sin(angle) * radius); var frame = (int)MathHelpers.Mod(angle * Mathf.Rad2Deg, 360); guns[i].sprite = frames[frame]; if (bulletSettings.prefab && fire == i) { var obj = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.prefab); if (obj) { obj.transform.position = guns[i].transform.position; obj.transform.rotation = guns[i].transform.rotation; var bulletBase = obj.GetComponent <BulletBase>(); if (bulletBase) { bulletBase.transform.eulerAngles = new Vector3(0, 0, -frame); bulletBase.velocity = obj.transform.rotation * new Vector3(bulletSettings.speed + Random.Range(0, 5), 0, 0); bulletBase.transform.Translate(bulletSettings.position, Space.Self); } obj.SetActive(true); } } if (bulletSettings.effectPrefab && fire == i) { var obj = AdvancedGameObjectPooler.GetAvailableObject(bulletSettings.effectPrefab); obj.transform.SetParent(guns[i].transform, false); obj.SetActive(true); } } rotation += -1 * Time.deltaTime; }