I need some help :)

So right, I’m trying to make a sort of editor for the circuit scripts in this thread, the way I plan for it to work is when when you place a circuit peace it adds it to 2 arrays, as each piece is a 1X1 square it can be represented as just its position on a X array and Y array, in my case this is 8x8 and that part works, but that is were I can make it work, then what I need is to is get the script from circuit pieces and add to there inputs four objects, one that is above, the one below, the one to the right and the one to the left… but my problem lies in getting the script, I cant find out how to do this? I need to get a the scripts but instead of the scripts the class? in that thread there is the “CircuitBlock” class and then all the different blocks, so I need to find the objects CircuitBlock? but I don’t know how to do this nor could I find how to do it?

this is my instantiating code:

using UnityEngine;
using System.Collections;

public class Instantiate : MonoBehaviour 
{
   private Vector3 screenPos;
   private Vector3 worldPos;
   public Transform prefab;
   private GameObject newInstance;
   private GameObject[] ArrayX;
   private GameObject[] ArrayZ;
   private int worldPosX;
   private int worldPosZ;

	
	void Start () 
	{
	 ArrayX = new GameObject[8];
	 ArrayZ = new GameObject[8];
	}
	
	void OnMouseDown() 
	{
	 screenPos = Input.mousePosition;
	 screenPos.z = 20;
     worldPos = Camera.main.ScreenToWorldPoint(screenPos);
     worldPos.x = Mathf.Round(worldPos.x);
	 worldPos.z = Mathf.Round(worldPos.z);
	 worldPos.y = Mathf.Round(worldPos.y);
     newInstance = Instantiate(prefab, worldPos, Quaternion.identity) as GameObject;
	 worldPosX = Mathf.RoundToInt(worldPos.x);
	 worldPosZ = Mathf.RoundToInt(worldPos.z);
     ArrayX[worldPosX] = newInstance;
	 ArrayZ[worldPosZ] = newInstance;
	 Debug.Log (worldPosX+" ,"+worldPosZ);
	//CircuitBlock Circ = newInstance.GetComponent<CircuitBlock>();
	//Circ.InputBlocks.add[ArrayX +1];
	//Circ.InputBlocks.add[ArrayX -1];
	//
	//Circ.InputBlocks.add[ArrayY +1];
	//Circ.InputBlocks.add[ArrayY -1];
	}
}

This is a block example:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// <summary>
//PowerBlocks give intinal power to the other blocks like a battery
/// </summary>
public class PowerBlock : CircuitBlock 
{ 
	
	protected override void StartBlock ()
	{
		Value = 1;
	}
	
	protected override void OnMouseOverAction()//I'm using this function to delete them, its not needed.
	{
	 if(Input.GetMouseButtonDown(1))
		{
        // Debug.Log("Right click on this object");
			Value = 0;
			Destroy (gameObject);
		}
	}
}

This is the simplest block I have, but I cant just use the script name as potentially there could be lots of different block types, so getting the class I guess would be easier then having tonnes of scripts to look for.

Ok, so just by changing GameObject to CircuitBlock seems to work :slight_smile: