Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cobispan · Feb 20 at 09:37 AM · arrayslists

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
 
 
         }
     }
 
 
     }
    
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding prefabs to a list or an array from a folder and instantiating them. 2 Answers

Get a List of the declared objects in a class 1 Answer

How to modify array values? 1 Answer

Is there a way to remove array entries in the editor? 4 Answers

Array of Lists null exception when adding to list. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges