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 swc991 · Sep 24, 2018 at 04:39 PM · collisioninstantiaterigidbody2dloopfloat

How to make object fall loop?

I have 2 game objects Ball 1 and Ball 2. Ball 1 is static and on the ground.Ball 2 is in the air due to greater y value and not in the camera view due to greater x value. What I want is when game starts Ball 2 should move along -x axis. Now if a button is pressed, Ball 2 should stop moving along x axis and start moving along -y axis i.e.it should fall.On fall if it collides with Ball 1 on the ground a new Ball 2 should instantiate on the same x, y axis and float value as the start of the game.Now the fallen Ball 2 should become Ball 1 so that if new instantiated Ball 2 collides with it on button press, another Ball 2 should instantiate and so on becoming a loop.

The problem I have is that when Ball 1 fells it does not fell straight down, so I made float value to be zero when button is clicked.Now new instantiated Ball 2 also has float value 0 and it does not move along y axis. I tried to fix this problem but couldn't. Once somehow I fixed a bit but it instantiated so many balls and crashed unity. I don't know much about prefabs should I create prefabs or not? My script to instantiate was on the Ball 2 but after crash I transferred it to Ball 1. What's the solution? My one and only script on Ball 1:

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      
      public class ballOne : MonoBehaviour
  {
  
      public GameObject balltwo;
      public Rigidbody2D rigidBody;
      public float speed;
  
  
      // Use this for initialization
      void Start()
      {
          speed = 5;
      }
  
      // Update is called once per frame
      void Update()
      {
          balltwo.transform.Translate(-speed * Time.deltaTime, 0, 0);
  
          if (Input.GetKey(KeyCode.DownArrow))
          {
              rigidBody.gravityScale = 1;
          }
          if (rigidBody.gravityScale == 1)
          {
              speed = 0;
          }
  
      }
      void OnTriggerEnter2D(Collider2D collision)
      {
          if (collision.gameObject.tag == "BallOne")
          {
              Instantiate(balltwo, new Vector2(transform.position.x + 6, transform.position.y + 2), transform.rotation);
              collision.gameObject.tag = "BallOne";
          }
      }
  }
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 swc991 · Sep 24, 2018 at 04:40 PM 0
Share

@Hellium Please help here too.

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

221 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

Related Questions

How to know when the player object falls between tiles in 2D game to take decesion of gameover 1 Answer

Destroying instantiated game objects from prefab when coliding with the ground 1 Answer

Unable to stop animation upon collision (2d, animation, rigidbody) 0 Answers

Unity Freezing after for loop 1 Answer

Instantiating a tile in place of another tile 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