Ejemplo n.º 1
0
    public void SpawnNewMolecule(int molType, Vector3 position)
    {
        KinMol _mol01 = Instantiate(molecule, position, Quaternion.identity);         //, zoneGO.transform);

        _mol01.gameObject.name = "mol_" + molCount;
        _mol01.type            = molType;
        _mol01.mySpawner       = this;
        _mol01.scale           = 0.04f;
        _mol01.zoneGO          = zoneGO;

        KinDiffuse _diffuse = _mol01.gameObject.GetComponent("KinDiffuse") as KinDiffuse;

        _diffuse.zoneGO = zoneGO;

        molCount++;
    }
Ejemplo n.º 2
0
    //private void OnTriggerEnter(Collider collider)
    //{
    //	{
    //		KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;
    //		if (molecule)
    //		{
    //			if (molecule.type == 3)
    //			{
    //				if ( Vector3.Dot(transform.right, (molecule.transform.position - transform.position)) > 0f)
    //				{
    //					molecule.GetComponent<Rigidbody>().AddForce(transform.right * 0.25f, ForceMode.Impulse);
    //				}
    //			}
    //		}
    //	}

    //}

    private void OnTriggerStay(Collider collider)
    {
        KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;

        if (molecule)
        {
            if (!molecule.myKinBind)
            {
                if (molecule.type == 3)
                {
                    Vector3 pushDir = -transform.right;
                    float   dot     = Vector3.Dot(pushDir, (molecule.transform.position - transform.position));
                    if (dot > 0f)
                    {
                        molecule.GetComponent <Rigidbody>().AddForce(pushDir * 0.01f, ForceMode.Impulse);
                    }
                    else if (dot < 0f)
                    {
                        molecule.GetComponent <Rigidbody>().AddForce(-pushDir * 0.01f, ForceMode.Impulse);
                    }
                }
            }
        }

        if (!molecule)
        {
            KinDiffuse diffuse = collider.gameObject.GetComponent("KinDiffuse") as KinDiffuse;
            if (diffuse)
            {
                //if (molecule.type == 3)
                {
                    Vector3 pushDir = -transform.right;
                    float   dot     = Vector3.Dot(pushDir, (diffuse.transform.position - transform.position));
                    if (dot > 0f)
                    {
                        diffuse.GetComponent <Rigidbody>().AddForce(pushDir * 0.01f, ForceMode.Impulse);
                    }
                    else if (dot < 0f)
                    {
                        diffuse.GetComponent <Rigidbody>().AddForce(-pushDir * 0.01f, ForceMode.Impulse);
                    }
                }
            }
        }
    }