Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 timurichk · Jul 13, 2018 at 02:03 PM · 2dscripting problemmovementinstantiateplatformer

Why isn't my instance of an object moving?

Hey, I'm pretty new to unity and am making an infinite runner at the moment. I made it so that the platforms under the character move instead of the actual character.However, when I clone the platform, it doesn't move, even though I have movement set up in it's update function. The first 2 place holder platforms I added in do move, so I am really stumped.

Here is the platform spawner script: public class EnviroHandler : MonoBehaviour {

 public GameObject ground;
 private float groundWidth;
 private float interval;
 private float intervalProgression = 0;
 private ArrayList groundList = new ArrayList();

 // Use this for initialization
 void Start () {
     groundWidth = ground.GetComponent<BoxCollider2D>().size.x;
     interval = ground.GetComponent<groundMovement>().speed;
     
 }
 
 // Update is called once per frame
 void Update () {
     
     if(intervalProgression >= interval){

         groundList.Add(Instantiate(ground, new Vector3(9.2f, -2, 0), Quaternion.identity));

         intervalProgression = 0;

     }else{
         intervalProgression += Time.deltaTime;
     }
 }

}

and here is the script each platform comes with:

public class groundMovement : MonoBehaviour {

 //declaration for certain attributes
 public int speed = 3;
 public float endPos;
 public float width;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     // Move the object to the left, using speed vasriable
     transform.Translate(Vector3.left * Time.deltaTime * speed);


     //destroy object when it moves off screen, based on x position and width
     if (transform.position.x >= endPos + width){
         Debug.Log("destroyed");
         Destroy(this);
     }
 }

}

Any help is greatly appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Strixie13 · Jul 13, 2018 at 02:17 PM

Check the object after it is instantiated, is the public int speed variable still set to three in the inspector on the clone? Sometimes it will show up as 3 when you create the object manually, but revert to 0 when it is instantiate if you declare it like that. (Thus it would be multiplying by 0 and would not move) If that is the case either do public static int speed = 3 or void Awake(){speed = 3;} to make sure it is declared.

Comment
Add comment · Show 3 · 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 madks13 · Jul 13, 2018 at 02:29 PM 0
Share

This is because the property values are copied from the prefab. The script does instantiate a prefab. If the prefab has speed set at 0, it will copy that value. Check the value of the prefab.

avatar image timurichk · Jul 13, 2018 at 02:29 PM 0
Share

Yeah I just checked and the clones don't even have the script. How can I fix that?

avatar image Strixie13 timurichk · Jul 13, 2018 at 02:34 PM 0
Share

You have to instantiate a prefab with the script rather than an object already in the scene. Get the object all set up how you want it, then drag and drop it into a folder. After that delete the object in the scene. Now go to your manager script, drag and drop the object from the folder onto the public GameObject ground.

Alternatively, if you already have a prefab (object in a folder) and made changes in the scene, click "apply" at the top right hand of the object's inspector window to apply the changes.

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

271 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

2D Movement with axis? 1 Answer

Instantiated clones using each other`s script 0 Answers

Can't change direction mid-jump 1 Answer

How to make a companion that trails character moves, and not collide? 0 Answers

Why do I double jump? This isn't supposed to happen... 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