private void Awake()
    {
        platformScript = transform.parent.gameObject.GetComponent <mainPlatformScript>();
        if (platformScript == null)
        {
            print("Couldn't find the platform script on the child collider's parent. Please attach one!");

            movingPlatformScript.enabled = false;
            return;
        }

        movingPlatformScript = gameObject.GetComponent <tempMovingPlatformScript>();
        if (movingPlatformScript == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find the moving platform script on the child collider. Please attach one!");
            }

            return;
        }

        platformTransform = transform.parent;
        if (platformTransform == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find a parent transform for the platform to function with!");
            }

            movingPlatformScript.enabled = false;
            return;
        }

        initialPosition = new Vector3(platformTransform.position.x, platformTransform.position.y, 0);

        platformRb2D = platformTransform.gameObject.GetComponent <Rigidbody2D>();
        if (platformRb2D == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find a rigidbody2d attached to the parent platform. Please attach one.");
            }

            return;
        }

        spriteRend = platformTransform.gameObject.GetComponent <SpriteRenderer>();
        if (spriteRend == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find a sprite renderer attached to the parent platform. Please attach one.");
            }

            return;
        }
    }
Exemplo n.º 2
0
    private void Awake()
    {
        platformMoveDelay = Mathf.Abs(platformMoveDelay);
        platformSpeed     = Mathf.Abs(platformSpeed);

        platformScript = transform.parent.gameObject.GetComponent <mainPlatformScript>();
        if (platformScript == null)
        {
            print("Couldn't find the platform script on the child collider's parent. Please attach one!");
            return;
        }

        if (positionArray == null)
        {
            gameObject.GetComponent <tempMovingPlatformScript>().enabled = false;
            return;
        }

        platformTransform = transform.parent;
        if (platformTransform == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find a parent transform for the platform to function with!");
            }

            gameObject.GetComponent <tempMovingPlatformScript>().enabled = false;
            return;
        }

        platformRb2D = platformTransform.gameObject.GetComponent <Rigidbody2D>();
        if (platformRb2D == null)
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Couldn't find a rigidbody2D attached to the platform!");
            }

            gameObject.GetComponent <tempMovingPlatformScript>().enabled = false;
            return;
        }

        if (positionArray.Length > 0)
        {
            positionArray[startPNum].transform.position = new Vector3(transform.parent.position.x, transform.parent.position.y, 0);

            foreach (GameObject posObj in positionArray)
            {
                posObj.transform.position = new Vector3(posObj.transform.position.x, posObj.transform.position.y, 0);
            }

            platformTransform.position = positionArray[startPNum].transform.position;
            endPNum = (positionArray.Length - 1);
        }
        else
        {
            if (platformScript.getPrintErrorBool())
            {
                print("Nothing is in the position array. Please attach GameObject points into the position array!");
            }

            gameObject.GetComponent <tempMovingPlatformScript>().enabled = false;
            return;
        }
    }