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 Forbidden_Duck · Feb 19, 2017 at 01:01 PM · c#gameobjectdeletepongintilization

I need help with Deleting and Initiating a gameobject

Hi, I am working a Pong Remake game and I am lost on how to delete the gameobject and initiate it again from it's default spawn position

I have a scoring system so in the code below right at the bottom you will see the points system

FYI It is a Ball for the game CODE:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Ball : MonoBehaviour
 {
     public float speed = 12;
     public GameObject original;
     public Text countTextL;
     public Text countTextR;
     private int countL;
     private int countR;
     void Start()
     {
         countL = 0;
         countR = 0;
         SetCountTextL();
         SetCountTextR();
         // Initial Velocity
         GetComponent<Rigidbody2D>().velocity = Vector2.right * speed;
     }
     float hitFactor(Vector2 ballPos, Vector2 racketPos,
                     float racketHeight)
     {
         return (ballPos.y - racketPos.y) / racketHeight;
     }
 
     void OnCollisionEnter2D(Collision2D col)
     {
         // Note: 'col' holds the collision information. If the
         // Ball collided with a racket, then:
         //   col.gameObject is the racket
         //   col.transform.position is the racket's position
         //   col.collider is the racket's collider
 
         if (col.gameObject.name == "RacketLeft")
         {
             // Calculate hit Factor
             float y = hitFactor(transform.position,
                                 col.transform.position,
                                 col.collider.bounds.size.y);
 
             // Calculate direction, make length=1 via .normalized
             Vector2 dir = new Vector2(1, y).normalized;
 
             // Set Velocity with dir * speed
             GetComponent<Rigidbody2D>().velocity = dir * speed;
         }
 
         if (col.gameObject.name == "RacketRight")
         {
             // Calculate hit Factor
             float y = hitFactor(transform.position,
                                 col.transform.position,
                                 col.collider.bounds.size.y);
 
             // Calculate direction, make length=1 via .normalized
             Vector2 dir = new Vector2(-1, y).normalized;
 
             // Set Velocity with dir * speed
             GetComponent<Rigidbody2D>().velocity = dir * speed;
         }
         if (col.gameObject.name == "WallLeft")
         {
             countR = countR + 1;
             SetCountTextR();
             if (countR >= 3)
             {
                 SceneManager.LoadScene("RightSide Scene");
             }
         }
         if (col.gameObject.name == "WallRight")
         {
 
             countL = countL + 1;
             SetCountTextL();
             if (countL >= 3)
             {
                 SceneManager.LoadScene("LeftSide Scene");
             }
         }
     }
     void SetCountTextL()
     {
         countTextL.text = countL.ToString();
     }
     void SetCountTextR()
     {
         countTextR.text = countR.ToString();
     }
 }
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 toddisarockstar · Feb 19, 2017 at 08:26 PM

 //spawn something;
 Instantiate (gameObject, Vector3.zero, Quaternion.identity);
         
 //object will self destruct!!!
 Destroy (gameObject);


in your situation i dont think the proficiency would matter in your game but as a general rule in game development its not considered good habit to actuall destroy things when you want them to temporarily dissapear. I would rececoment simply snapping the ball's position off camera or temporarily making it transparent instead till you want to move it back into game play.

Comment
Add comment · Show 2 · 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 Forbidden_Duck · Feb 20, 2017 at 07:18 AM 0
Share

I see what you mean. When I tried it, the ball hit the wall paused then continued moving then it wouldn't do anything

  1. I can't get the ball to reset to the middle That is all I need to happen is the ball to go back to the middle where it first spawns.

avatar image toddisarockstar Forbidden_Duck · Feb 22, 2017 at 11:31 PM 0
Share
 Vector3 startspot;
 
 void start(){
 
 startspot=transform.position;
 }
 
 void update(){
 
 when you wan the ball to come back just say
 transform.position = startspot;
 }
 
 

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

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

collider.gameObject.GetComponent doesn't have correct values yet it has the correct name 0 Answers

Status Effect Help 0 Answers

Getting collision for individual gameobjects in an array and changing properties of other gameobjects from that array 0 Answers

How to make a floppy object 1 Answer

how to communucate GameObject and Script by tag? 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