C# Reference

I have an on click command set up on a couple of my objects what I am needing help doing is when an object is clicked it sets is transform as the engineGEO of the FindProceduralProperties.cs script. The FindProceduralProperties.cs script has a public Transform called engineGEO. This script is on an object called MyGui.

using UnityEngine;
using System.Collections;

public class OpenLids : MonoBehaviour 
{
	
	public GameObject thiscrate;
	public GameObject info;



void OnMouseDown() 
	{
    	info.SetActive (true);
		GameObject varGameObject = GameObject.Find("MyGui"); // Finds the main ship
		varGameObject.GetComponent<FindProceduralProperties>().engineGEO = thiscrate.transform; // Finds the fly script and turns it off if we die
	}
void FixedUpdate ()
	{
		if (Input.GetKey ("escape"))
		{
			GameObject varGameObject = GameObject.Find("MyGui"); // Finds the main ship
			varGameObject.GetComponent<FindProceduralProperties>().engineGEO = null ; // Finds the fly script and turns it off if we die
			info.SetActive (false);
				
		}
	}
	
}

Can you post the scripts? trying to imagine them is hard.

–

I have managed to get it scripted out my problem right now is I need to set the transform back to empty so when I click on the next one it can fill it in. I will add to the top my script using to do this. What the problem is, is that when I click on the next one with it seting it to null it wont set the transform. I have the script shown on all my objects.

–

What I need to do is set the transform when the escape key is pressed back to empty so I can accept an new item into it.

–

You have Input inside FixedUpdate which is not advised, that might be run many times per frame or not at all in a frame. That should definitely go in Update or LateUpdate.

–

It should also be GetKeyDown, not GetKey. Also it's better to use KeyCode enums instead of strings.

–

1 Answer

1

It was working the script that loads the substance had the old one loaded and would not load a new one so I ended up having to change the hole setup arround. Thanks for every ones help.