Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MonkizakiTheGOD · Feb 08, 2020 at 04:33 PM · scripting problemheightendless runnerplatformsgenerator

Endless Runner platform Heigh generator not working.

So I have a script to make my platforms spawn in different heights since it was spawning at places that were out of the camera then you had to add a function that would limit the heights within a Max and Min height, to keep it within camera range. My problem is, every time I set the function, when I take "//" off (which means I'm making it active, take place) then the function stops working and I have no idea why.

This is my script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlatformGenerator : MonoBehaviour
 {
 
     public GameObject Wood;
     public Transform GenerationPoint;
     public float DistanceBetween;
 
     private float PlatformWidth;
 
     private float MinHeight;
     public Transform MaxHeightPoint;
     private float MaxHeight;
     public float MaxHeightChange;
     private float HeightChange;
 
     void Start()
     {
         PlatformWidth = Wood.GetComponent<BoxCollider2D>().size.x;
         MinHeight = transform.position.y;
         MaxHeight = MaxHeightPoint.position.y;
     }
 
     void Update()
     {
         if(transform.position.x < GenerationPoint.position.x)
         {
             HeightChange = transform.position.y + Random.Range(MaxHeightChange, -MaxHeightChange);
 
             //if (HeightChange > MaxHeight)
             {
                 //HeightChange = MaxHeight;
             }
             //else if (HeightChange < MinHeight)
             {
                 //HeightChange = MinHeight;
             }
 
             transform.position = new Vector3(transform.position.x + PlatformWidth + DistanceBetween, HeightChange, transform.position.z);
             Instantiate(Wood, transform.position, transform.rotation);
         }
     }
 }

So, here is my script. If you notice in the update section, at the bottom, right after HeightChange = transform.position.y + Random.Range(MaxHeightChange, -MaxHeightChange); I have the rules to make the spawning be within a certain range. I'll say, I am following a video to get make this possible and I am doing everything the video says but it's been giving me this problem so I'm taking it to Unity itself.

Thanks, peace

Comment
Add comment · Show 1
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
avatar image dexterti369 · Aug 30, 2021 at 06:28 PM 0
Share

Im having the same issue

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Kill : MonoBehaviour
 {
 
     
     public GameObject player;
     public GameObject springPrefab;
     public GameObject platformPrefab;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     private void OnTriggerEnter2D(Collider2D collision)
     {
 
      if(collision.gameObject.name.StartsWith("Platform"))
         {
             if (Random.Range(1, 7) == 1){
 
                 Destroy(collision.gameObject);
                 Instantiate(springPrefab, new Vector2(Random.Range(-5.5f,5.5f), player.transform.position.y + (14 + Random.Range(0.2f, 1f))), Quaternion.identity);
             
             }else {
 
                 collision.gameObject.transform.position = new Vector2(Random.Range(-5.5f,5.5f), player.transform.position.y + (14 + Random.Range(0.5f, 1f)));
 
             }
 
 
         }else if(collision.gameObject.name.StartsWith("Spring"))
         {
 
 
              if (Random.Range(1, 7) == 1){
 
                 collision.gameObject.transform.position = new Vector2(Random.Range(-5.5f,5.5f), player.transform.position.y + (14 + Random.Range(0.2f, 1f)));
             
             }else {
 
                 Destroy(collision.gameObject);
                 Instantiate(platformPrefab, new Vector2(Random.Range(-5.5f,5.5f), player.transform.position.y + (14 + Random.Range(0.5f, 1f))), Quaternion.identity);
 
             }
 
         }
 
     }
 }

Character freezes after two jumps and platforms aren't being generated

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

212 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 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

How to Instantiate platforms with certain space inbetween each platform (Endless Runner) 0 Answers

[SOLVED] My crouch script, wont go low enough! 0 Answers

How to create a code generator? 1 Answer

C# MultipleChoice 0 Answers

Collider fires consistently, but Trigger does not? 0 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