コード例 #1
0
 public void Detach(Module first, bool last)
 {
     for (int i = 0; i < 4; i++)
     {
         Module neighbour = relations [i];
         if (neighbour != null)
         {
             neighbour.RemoveRelation(Conversion.FlipDirection(i), last);
         }
     }
     //clear relevant data
     main.Detach(first.transform.position);
 }
コード例 #2
0
ファイル: FloatingComponent.cs プロジェクト: sam6321/Decay
    public bool TryReturnToSpawner()
    {
        ShipStructure structure = shipComponent.AttachedStructure;

        if (!enabled && shipComponent.Detach())
        {
            rigidbody2D = gameObject.AddComponent <Rigidbody2D>();
            rigidbody2D.gravityScale = 0;

            // Pick a random direction away from structure and eject the component in that direction
            Vector2 direction = transform.position - structure.transform.position;
            rigidbody2D.AddForce(direction.normalized * 100);

            detachSounds.PlayRandomOneShot(audioSource);

            enabled = true;
            //renderer.maskInteraction = oldMaskInteraction;

            if (particlesOnDetach)
            {
                Instantiate(particlesOnDetach, transform.position, Quaternion.identity);
            }

            if (SpawnTag != null && !destroyOnDetach)
            {
                SpawnTag.spawner.Add(this);
            }
            else
            {
                // Was either not owned by a spawner, or we're set to destroy on detach
                Destroy(gameObject);
            }

            return(true);
        }

        return(false);
    }