Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 OatMilkLover · Dec 02, 2020 at 10:54 AM · transform.positioncoroutinesinstantiate prefabparameters

Platform cannot move up

I am making a 2D game where you have to drop down platforms and avoid being brought up to a certain point. Unfortunately, I cannot game the platforms to move up. I have tried both with Vector3.MoveTowards and rb.velocity, the latter of which I did not choose because I need the platforms to be static. With the MoveTowards method, it still doesn't work. Here are the scripts:

 //START SPAWNING PLATFORMS
 void Start()
 {
     StartCoroutine(InstantiatePlatforms());
 }

 void Update()
 {
     //PLATFORM MOVEMENT
     platform.GoUp(upSpeed);
 }

 // SPAWN PLATFORMS
 public IEnumerator InstantiatePlatforms()
 {
     GameObject spawnedObject = platforms[Random.Range(0, platforms.Length)];

     Vector3 spawnPosition = new Vector3(Random.Range(-1, 3), -10, 0);
     Instantiate(spawnedObject, spawnPosition, Quaternion.identity);

     yield return new WaitForSeconds(1);
     StartCoroutine(InstantiatePlatforms());
 }

 void IncreaseDifficulty()
 {
     upSpeed++;
 }

and the script for the platforms:

 public void GoUp(float upSpeed)
 {
     transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, 8, transform.position.z), Time.deltaTime * upSpeed);
 }

I have never worked with 2D and am wondering where I messed up. Thank you in advance!

BTW I set upSpeed to 10 and assigned every public variable.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by xxmariofer · Dec 02, 2020 at 11:34 AM

You need to try and debug it yourself, unity is for sure giving you a null reference exception. your issue is that you never assign platform in your script

Simply move the GoUp script from the platforms class to the Update and remove the Update from the spawingn platforms script

Comment
Add comment · Share
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
0

Answer by OatMilkLover · Dec 02, 2020 at 12:56 PM

alt text

@xxmariofer Thank you for your help but it still does not seem to work. Also could you please elaborate on the second part? Do I move the code from the GoUp method into the spawner's Update? Sorry if I am just dumb and this is a really simple problem.

Edit: I get the second part of your post but I would like to be able to increase the difficulty via increasing the speed at which the platforms move up. Is there anyway I can do this with your solution? Thank you for your help.


thing.png (11.2 kB)
Comment
Add comment · Share
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

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

142 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

Related Questions

Can I use StartCoroutine(CoroutineName()) instead of StartCoroutine("CoroutineName") from another script? 1 Answer

Instantiated clone GameObject spawning at wrong position. 2 Answers

coroutine in update method 1 Answer

[SOLVED ]Instantiate prefab position 2 Answers

How to spawn evenly spaced game objects and move them in a circular path? 1 Answer


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