public override void Setup() { base.Setup(); soundCtrl = GetComponentInChildren <BulletSoundController>(); spawnSticky = false; stickyObject = null; }
protected override void ObjectSpawnEvent() { muzzleFlashParticle.transform.position = shotPosition; muzzleFlashParticle.transform.eulerAngles = new Vector3(0, 0, shotAngle); muzzleFlashParticle.Play(); soundCtrl.Shot(); bulletParticle.Play(); spawnSticky = false; stickyObject = null; Ray ray = new Ray(transform.position, transform.right); RaycastHit hitInfo; if (Physics.SphereCast(ray, bulletCollider.radius, out hitInfo, 100f, layersToCheck)) { if (hitInfo.transform.gameObject.layer == LayerMask.NameToLayer("Obstacle")) { stickyObject = PoolManager.instance.GetPooledObject(stickyObjectType, gameObject).GetComponent <StickyObject>(); spawnSticky = stickyObject.Init(hitInfo.point, hitInfo.normal, Quaternion.LookRotation(Vector3.forward, hitInfo.normal)); } } base.ObjectSpawnEvent(); }
IEnumerator DelaySticky(StickyObject obj) { Destroy(obj.GetComponent<Rigidbody>()); obj.GetComponent<StickyObject>().group = group; obj.transform.parent = group.transform; yield return null; }
void MergeGroups(StickyObject other) { Debug.Log("Merge groups"); other.transform.parent = null; if (other.group.transform.childCount == 0) { Destroy(other.group.gameObject); } other.group = null; AddToOwnGroup(other); }
void AddToOwnGroup(StickyObject obj) { StartCoroutine(DelaySticky(obj)); }