Exemple #1
0
    public void OnValidate()
    {
        if (Application.isPlaying == true)
        {
            if (CheckErrors() == true)
            {
                return;
            }

            usingGravity = false;                    // remains false if forceing no gravity or if projectile doesn't use it
            if (shot.GetComponent <Rigidbody>())     // verify rigidbody
            {
                if (gravity == GravityUsage.Gravity) // force gravity
                {
                    usingGravity = true;
                }
                else
                {
                    if (shot.GetComponent <Rigidbody>().useGravity == true && gravity == GravityUsage.Default)                        // use gravity if projectile does
                    {
                        usingGravity = true;
                    }
                }
            }
            curInaccuracy = inaccuracy;
            // compute missing value: shotSpeed, maxRange, shotDuration
            if (shotSpeed <= 0)
            {
                shotSpeed = maxRange / shotDuration;
            }
            else if (maxRange <= 0)
            {
                maxRange = shotSpeed * shotDuration;
            }
            else                 // compute shotDuration even if all 3 are set to keep math consistant
            {
                shotDuration = maxRange / shotSpeed;
            }
        }
    }