Ejemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("MeshObject"))
        {
            Vector3 contact = collision.GetContact(0).point;

            if (GameObject.FindGameObjectWithTag("GameController").GetComponent <BackgroundGenerator>().inside)
            {
                // If configuration is "inside"
                MeshGeneratorInside meshGenIn = GameObject.FindGameObjectWithTag("GameController").GetComponent <MeshGeneratorInside>();
                Vector3             force     = collision.relativeVelocity; // to create matter add the velocity
                // Destroy and create a new node from the impact force
                meshGenIn.ImpactEffect(contact, force);
            }
            else
            {
                // If configuration is "outside"
                MeshGeneratorOutside meshGenOut = GameObject.FindGameObjectWithTag("GameController").GetComponent <MeshGeneratorOutside>();
                Vector3 force = collision.relativeVelocity.normalized; // to create matter add the velocity
                // Destroy and link to the nearest existing node from the impact direction
                meshGenOut.ImpactAddEffect(contact, force);
            }

            // Play the "shot" sound and destroy it after 1 second (it is an instantiation to delete this object and be able to play the sound)
            GameObject sound = Instantiate(destroySound, contact, Quaternion.identity);
            sound.GetComponent <AudioSource>().Play();
            Destroy(sound, 1f);

            // Delete this shot
            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 2
0
 void Start()
 {
     if (inside)
     {
         // Configuration is "inside"
         GenerateObject();           // Generate the object (a cube of "size" length)
         MeshGeneratorInside meshGenIn = GetComponent <MeshGeneratorInside>();
         meshGenIn.CreateNodes(obj); // Pass it to the MeshGeneratorInside for inside configuration
     }
     else
     {
         // Configuration is "outside"
         GenerateObject();            // Generate the object (a cube of "size" length)
         MeshGeneratorOutside meshGenOut = GetComponent <MeshGeneratorOutside>();
         meshGenOut.CreateNodes(obj); // Pass it to the MeshGeneratorOutside for outside configuration
     }
 }