// Use this for initialization void Start() { this.container = this.transform.parent.gameObject.GetComponent<ContainerBehaviour>(); }
// This method place each platform just up of the character to create the game levels. public void PlacePlatform() { //Check if the variable "counterAchieve" reachs the number of platforms per level. if (counterAchieve == containersPerLevel) { //If the current container has an animation... if (currentContainerAnimator != null) { currentContainerAnimator.enabled = false; //...then disable it... currentContainerAnimator = null; //...and set it as null. } counterContainers++; //Increase this counter to use the next container of cycle. //If the array "containersCycle" has reached its limit... if (counterContainers == containersCycle.Count) { counterContainerSpeed++; //...increase the speed of the containers... //...check if the array "containerSpeed" has reached its limit... if (counterContainerSpeed == containerSpeed.Length) { counterContainerSpeed = 0; //...and restart this counter to use the array "containerSpeed" again. } currentContainerSpeed = containerSpeed [counterContainerSpeed]; //Get the speed for the containers. counterContainers = 0; //...restart this counter to use the array "containersCycle" again. } container = containersCycle [counterContainers]; //Get the corresponding container of cycle. pointPlatform = container.GetChild(0); //Get the child "pointPlatform" of the container. //If the current container has an animation... if (containerAnimatorList [counterContainers] != null) { currentContainerAnimator = containerAnimatorList [counterContainers]; //...get it... currentContainerAnimator.speed = currentContainerSpeed; //...set the current speed... currentContainerAnimator.enabled = true; //...and show the animation. } counterAchieve = 0; //Reset this counter to use it again. } counterAchieve++; //Increase this counter to reach the number of platforms per level. Transform platform = platformsList [counterPlatforms]; //Get the next platform in the platform list. platform.SetParent(pointPlatform); //Set this platform as child of current container. //Depending on the container, this one will have a different configuration switch (container.name) { case "Container_static": //Static container, the platform will be positioned randomly in x and y axis. platform.localPosition = new Vector3(Random.Range(minX, maxX), Random.Range(minY, maxY), 0); break; case "Container_horizontal": //Horizontal movement, the platform will be positioned randomly in y axis. platform.localPosition = new Vector3(0, Random.Range(minY, maxY), 0); break; case "Container_vertical": //Vertical movement, the platform will be positioned randomly in x axis. platform.localPosition = new Vector3(Random.Range(minX, maxX), 0, 0); break; default: //Circular, rectangular and triangular container. platform.localPosition = Vector3.zero; //The platform will be positioned in the center of container. ChangeAnimationDirection(); //Change or not the direction of the container's animation. break; } platform.localScale = new Vector3(Random.Range(minWidthSize, maxWidthSize), 1, 1); //Change the platform's size. Transform fly = fliesList [counterFlies]; //Get the next fly in the flies list. fly.SetParent(platform); //Set the next fly as child of the platform. fly.localPosition = new Vector3(0, -0.4f, 0); //Change the fly's local position. container.position = containerStartPosition; //Reset container's position. currentScriptContainer = container.GetComponent <ContainerBehaviour>(); //Get current container's containerBehaviour script. counterPlatforms++; //Increase this counter for next time we enter to this method, use the next platform in the list. counterFlies++; //Increase this counter for next time we enter to this method, use the next fly in the list. //If the array "platformsList" has reached its limit... if (counterPlatforms == platformsList.Count) { counterPlatforms = 0; //...restart this counter to use the array again. } //If the array "fliesList" has reached its limit... if (counterFlies == fliesList.Count) { counterFlies = 0; //...restart this counter to use the array again. } }
// Use this for initialization void Start() { this.container = this.transform.parent.gameObject.GetComponent <ContainerBehaviour>(); }
void OnEnable() { containerBehaviour = (ContainerBehaviour)target; }