private void BindTo(ChainTower other) { var damageLine = new Segment(transform.position, other.transform.position); Vector2 direction = transform.position - other.transform.position; var laser = Instantiate(laserPrefab, Vector2.Lerp(transform.position, other.transform.position, 0.5f), Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.right, direction))); var ps = laser.GetComponent <ParticleSystem>(); var shape = ps.shape; shape.radius = Vector2.Distance(transform.position, other.transform.position) / 2 - 0.2f; // var gunRotation = Vector2.SignedAngle(Vector2.right, direction); gun.transform.rotation = Quaternion.Euler(0, 0, gunRotation + 180); // var binding = new Binding { bindedTower = other, damageLine = damageLine, laser = laser, gun = gun, idle = false }; bindings.Add(binding); CanBind = maxBindingCount > bindings.Count; gun = Instantiate(gun, transform); if (!CanBind) { gun.SetActive(false); } other.Bind(this, damageLine, laser, gunRotation); }
private void Unbind(ChainTower other) { for (int i = 0; i < bindings.Count; i++) { if (bindings[i].bindedTower == other) { if (bindings[i].laser != null) { var particleSystem = bindings[i].laser.GetComponent <ParticleSystem>(); particleSystem.Stop(); Destroy(bindings[i].laser, particleSystem.main.startLifetime.constantMax); } if (bindings[i].gun != null) { Destroy(bindings[i].gun); } bindings.RemoveAt(i); CanBind = maxBindingCount > bindings.Count; if (gun != null) { gun.SetActive(CanBind); } } } }
private void Bind(ChainTower other, Segment damageLine, GameObject laser, float gunRotation) { gun.transform.rotation = Quaternion.Euler(0, 0, gunRotation); var binding = new Binding { bindedTower = other, damageLine = damageLine, laser = laser, gun = gun, idle = true }; bindings.Add(binding); CanBind = maxBindingCount > bindings.Count; gun = Instantiate(gun, transform); if (!CanBind) { gun.SetActive(false); } }