- Home /
Arrays Progressive Difficulty
Hey, I have been trying to add progressive difficulty to my game that I am trying to complete and been having a pretty difficult time trying to write the right code. It is a "Kaboom style game" and I want to add an array or list of values to the "Speed" of the "Apple tree" , the "chanceToChangedirection" , and "secondsBetweenAppleDrops" . I want each element in the list to have a different difficulty going from 0 the easiest to more difficult. A level counter as well is what i am aiming for to increase over time. How do I change the code so it shows an array or list for each element listed above? And how do should I implement a level counter? Public float speed I want to be changed to show a list, Public float chanceToChangeDirection and Public float secondsBetweenAppleDrops.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AppleTree : MonoBehaviour
 {
     // Prefab for instantiating apples
     public GameObject applePrefab;
 
     // Speed at which the AppleTree moves in meters/second
 
     public float speed;
     
 
     //Distance where AppleTree turns around
     public float leftandRightEdge = 15f;
 
     // Chance that the AppleTree will change directions
     public float chanceToChangeDirections = 0.1f;
 
     // Rate at which apples will be instantiated
     public float secondsBetweenAppleDrops = 2f;
 
 
     // Second prefab for instantiating bombs
     public GameObject bombPrefab;
 
     //Rate at which bombs will be instantiated
     public float secondsBetweenBombDrops = 1f;
 
 
 
     void Start()
     {
         // Dropping apples every second
         InvokeRepeating("DropApple", 2f, secondsBetweenAppleDrops);
         // Dropping bombs every second
         InvokeRepeating("DropBomb", 1f, secondsBetweenBombDrops);
 
      }
 
     void DropApple()
     {
         GameObject apple = Instantiate(applePrefab) as GameObject;
         apple.transform.position = transform.position;
 
     }
     void DropBomb()
     {
         GameObject bomb = Instantiate(bombPrefab) as GameObject;
         bomb.transform.position = transform.position;
     }
         void Update()
     {
 
         
         // Basic Movement
         Vector3 pos = transform.position;
         pos.x += speed * Time.deltaTime;
         transform.position = pos;
         // Changing Direction
         if (pos.x < -leftandRightEdge)
         {
             speed = Mathf.Abs(speed); // Move right
         }
         else if (pos.x > leftandRightEdge)
         {
             speed = -Mathf.Abs(speed); // Move left
         }
         
     }
     void FixedUpdate()
     {
         // Changing Direction Randomly
         if (Random.value < chanceToChangeDirections)
         {
             speed *= -1; // Change direction
 
 
         }
     }
 
 
     }
    
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                