'ello folks, I have just put together a few scripts which turn particles on and off when clicking on the object itself or another object. At them moment I have three planes with textures on to represent what I want to be highlighted with particles. I also have three different scripts, each essentially the same but slightly different.
Here is one of the scripts contents (like I say, all are essentially the same):
using UnityEngine;
using System.Collections;
public class SelectRedTexture : MonoBehaviour {
public bool isMouseOver = false;
public bool redPegSelected = false;
public GameObject redTarget1;
public GameObject redTarget2;
public GameObject redTarget3;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(redPegSelected == false)
{
particleEmitter.enabled = false;
particleEmitter.ClearParticles();
}
}
void OnMouseOver()
{
isMouseOver = true;
if(Input.GetButtonUp("Fire1") isMouseOver == true)
{
// textureIsSelected = true;
redPegSelected = true;
if(isMouseOver == true redPegSelected == true)
{
particleEmitter.enabled = true;
SelectYellowTexture syt = (SelectYellowTexture)redTarget1.GetComponent("SelectYellowTexture");
syt.yellowPegSelected = false;
// SelectGreenTexture sgt = (SelectGreenTexture)redTarget2.GetComponent("SelectGreenTexture");
// sgt.redPegSelected = false;
SelectBlueTexture sbt = (SelectBlueTexture)redTarget3.GetComponent("SelectBlueTexture");
sbt.bluePegSelected = false;
}
}
}
void OnMouseExit()
{
isMouseOver = false;
}
}
So, that is for my red texture, I also have blue and yellow ones as well. The problem is that if I click from red > yellow > red > yellow > red; the third time I click the red object, it gets destroyed… I have nothing in my code (as you can see) which points towards any form of deletion. I can go from red > blue, blue > red, blue > yellow or yellow > blue as many times as I like and it does not delete. I’m confused as to why this is happening…![]()
Any ideas would be most welcome,
thanks!
Edit: I just tried going from red > blue > red > blue > red and that also deletes the red object…