Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Destroy instance clone of gameobject

$
0
0
I am creating a small interaction where you click on a table and a small animation plays in response. What I'm getting caught up on is that when I instantiate the click I cannot rid the click object from the game. This has ended up with me bogging it down with too many objects in scene. if you guys could take a look at my code I would greatly appreciate it! As I have been looking to the answer to this problem for hours now haha! the fist block of code is in java script and the second is in c# #pragma strict var touch : GameObject; function OnCollisionEnter (other : Collision) { //public float initializationTime; if (other.transform != transform && other.contacts.length!=0) { for (var i = 0; i < other.contacts.length; i++) { Instantiate(touch, other.contacts[i]. point,Quaternion.identity); Destroy(GameObject.Find("Click(Clone)"),10); } } using UnityEngine; using System.Collections; public class ImageSequenceTextureArray : MonoBehaviour { //An array of Objects that stores the results of the Resources.LoadAll() method private Object[] objects; //Each returned object is converted to a Texture and stored in this array private Texture[] textures; //With this Material object, a reference to the game object Material can be stored private Material goMaterial; //An integer to advance frames public int frameCounter = 0; void Awake() { //Get a reference to the Material of the game object this script is attached to this.goMaterial = this.renderer.material; } void Start () { //Load all textures found on the Sequence folder, that is placed inside the resources folder this.objects = Resources.LoadAll("Sequence", typeof(Texture)); //Initialize the array of textures with the same size as the objects array this.textures = new Texture[objects.Length]; //Cast each Object to Texture and store the result inside the Textures array for(int i=0; i < objects.Length;i++) { this.textures[i] = (Texture)this.objects[i]; } } void Update () { //Call the 'PlayLoop' method as a coroutine with a 0.04 delay StartCoroutine("Play",0.00f); //Set the material's texture to the current value of the frameCounter variable goMaterial.mainTexture = textures[frameCounter]; } //The following methods return a IEnumerator so they can be yielded: //A method to play the animation in a loop IEnumerator PlayLoop(float delay) { //Wait for the time defined at the delay parameter yield return new WaitForSeconds(delay); //Advance one frame frameCounter = (++frameCounter)%textures.Length; //Stop this coroutine StopCoroutine("PlayLoop"); } //A method to play the animation just once IEnumerator Play(float delay) { //Wait for the time defined at the delay parameter yield return new WaitForSeconds(delay); //If the frame counter isn't at the last frame if(frameCounter < textures.Length-1) { //Advance one frame ++frameCounter; /* if(frameCounter >= 400) { objects =null; textures = null; goMaterial = null; frameCounter = frameCounter - 400; } */ } Destroy(GameObject.Find("Touch"),10); //Stop this coroutine StopCoroutine("Play"); } }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>