コード例 #1
0
 void setPlateToGo(GameObject plateToGo)
 {
     if (isUp)
     {
         isUp = false;
         transform.position = new Vector3(transform.position.x, 0.2f, transform.position.z);
     }
     movesCounter++;
     plate.SendMessage("freePlate");
     plate.SendMessage("makeNeighbourNotViableToGo");
     isGoing    = true;
     vectorToGo = FunctionHelperScript.makeVersor(new Vector3(transform.position.x, 0, transform.position.z), new Vector3(plateToGo.transform.position.x, 0, plateToGo.transform.position.z));
     plate      = null;
 }
コード例 #2
0
    float fireArrow(GameObject plateToAttack)
    {
        Vector3 forceVersor = FunctionHelperScript.makeVersor(transform.position, plateToAttack.transform.position);

        forceVersor = new Vector3(forceVersor.x, forceVersor.y + 1, forceVersor.z);
        forceVersor = forceVersor / FunctionHelperScript.vectorLength(forceVersor);

        float forceToAdd;

        if (onBuilding)
        {
            float bHeight;
            if (plateType == 2)
            {
                bHeight = 0.8f;
            }
            else
            {
                bHeight = 0.53f;
            }
            float length = FunctionHelperScript.vectorLength(new Vector3(transform.position.x, 0, transform.position.z), plateToAttack.transform.position);
            forceToAdd = (9.81f * Mathf.Pow(length, 2)) / (length + bHeight);
            forceToAdd = Mathf.Sqrt(forceToAdd);
        }
        else
        {
            forceToAdd = 3.132f * Mathf.Sqrt(FunctionHelperScript.vectorLength(transform.position, plateToAttack.transform.position));
        }


        GameObject arrowCopy = Instantiate(arrow, transform.position, Quaternion.identity);
        Rigidbody  arrowRb   = arrowCopy.GetComponent <Rigidbody>();

        arrowRb.AddForce(forceVersor * forceToAdd * 10);
        float timeToDestroyArrow = (2 * forceToAdd) / 9.81f;

        Destroy(arrowCopy, timeToDestroyArrow - 0.1f);
        return(timeToDestroyArrow);
    }