Destroying and Creating a GameObject
Hi,
I am working on a remake of pong when I was just testing something when I realized when I was running
Destroy(this);
it didn't do anything
This is the whole script for the gameObject "Ball"
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SocialPlatforms;
public class PauseScript : MonoBehaviour {
// Use this for initialization
void Start()
{
Destroy(this);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Instantiate(this);
}
}
}
Answer by whereswaldo · Jan 29, 2017 at 05:00 AM
Here's what you want but in JavaScript
function Start () {
Destroy(gameObject);
}
var remains: GameObject;
function Update()
{
if (Input.GetKeyDown(Return))
{
Instantiate(remains, transform.position, transform.rotation);
}
}
Hey the Destroy code works but the Instantiate doesn't
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SocialPlatforms;
public class PauseScript : $$anonymous$$onoBehaviour {
void Start()
{
Destroy(gameObject);
}
GameObject remains;
void Update()
{
if (Input.any$$anonymous$$eyDown)
{
Instantiate(remains);
}
}
}
Your answer
Follow this Question
Related Questions
GameObject.Destroy(gameObject); Not Working? 0 Answers
I need help with Deleting and Initiating a gameobject 1 Answer
Making someone happen after x amounts of seconds and only once 0 Answers
Why i can't acces a global list in my class from OnDestroy() function 0 Answers
(SOLVED) Destroy(gameObject) doesn't destroy the gameObject, only disables behaviours. 0 Answers