Пример #1
0
 void OnCollisionEnterasd(Collision other)
 {
     if (rb != null)                         //TODO: this if statement is temporary, not a real solution
     {
         if (Spawner != null)
         {
             if (other.transform.tag == "Unit") //&& other.gameObject != Spawner && other.GetType() == typeof(BoxCollider) && OnDifferentTeam(other.gameObject)){
             {
                 if (other.gameObject != Spawner && other.GetType() == typeof(BoxCollider) && OnDifferentTeam(other.gameObject))
                 {
                     GameObject hitUnit = other.gameObject;
                     Cube       hitCube = hitUnit.GetComponent <Cube>();
                     hitCube.TakeDamage(damage, rb.velocity);
                     Rigidbody hitRig = hitUnit.GetComponent <Rigidbody>();
                     hitRig.AddForce(rb.velocity.normalized * impactForce, ForceMode.Impulse);
                     CubePool.AddToLaserPool(gameObject);
                 }
             }
         }
         if (other.transform.tag == "Laser" && OnDifferentTeam(other.gameObject))
         {
             LaserCollision(other.gameObject);
         }
     }
 }
Пример #2
0
 void Despawn()
 {
     if (Time.time > spawnTime + DespawnTime)
     {
         CubePool.AddToLaserPool(gameObject);
     }
 }
Пример #3
0
    void LaserCollisionOld(GameObject other)
    {
        print("BROKEN");
        gameObject.GetComponent <BoxCollider>().enabled  = false;
        gameObject.GetComponent <MeshRenderer>().enabled = false;
        GameObject        deathCube  = (GameObject)Resources.Load("DeathCube");
        List <GameObject> cubes      = new List <GameObject>();
        float             cubeAmount = gameObject.transform.localScale.z / 0.25f;

        cubeAmount = cubeAmount / cubeAmountMod;
        deathCube.transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, 0.25f);
        deathCube.GetComponent <MeshRenderer>().material = GetComponent <MeshRenderer>().material;
        float   startZ        = transform.position.z - (transform.localScale.z / 2);
        Vector3 startPosition = new Vector3(transform.position.x, transform.position.y, startZ);
        Vector3 additive      = new Vector3(0, 0, 0);

        for (int i = 0; i < cubeAmount; i++)
        {
            cubes.Add((GameObject)Instantiate(deathCube, startPosition + additive, Quaternion.identity));
            additive += new Vector3(0, 0, 0.25f * cubeAmountMod);
        }
        foreach (GameObject cube in cubes)
        {
            if (rb != null)
            {
                cube.GetComponent <Rigidbody>().AddForce(rb.velocity * 10);
            }
        }
        GetComponent <BoxCollider>().enabled = false;
        CubePool.AddToLaserPool(gameObject);
    }
Пример #4
0
    void LaserCollision(GameObject other)
    {
        //gameObject.GetComponent <MeshRenderer>().enabled = false;
        Vector3 vel = rb.velocity;

        gameObject.GetComponent <BoxCollider>().enabled = false;
        GetCubes();
        SetupSubs();
        EnableSubs();
        PrepDeathSubCube();
        AddVelocityToSubs(vel);

        CubePool.AddToLaserPool(gameObject);
    }