Prefab with script wont override values

So, I have an elevator prefab with a button. The button has a script that raises and lowers the elevator platforms.

There are 2 elevator platforms, and 4 total control panels.

ButtonA1
ButtonA2

These are linked to Elevator A in the script (drag and drop into the script attribute)

ButtonB1
ButtonB2

These are linked to Elevator B in the script (drag and drop into the script attribute).

All the buttons move both elevators, no mater what. I’ve deleted the button prefab and just made a new object with the script attached - same thing. I’ve tried everything short of writing a custom script for each elevator, which isn’t right, as it’s the same exact script.

Here is what the script attribute looks like:

1359756--67620--$elevatorscript_zps25cc1f86.png

Is there a setting that I’m forgetting about?

so… where in all those options do you specify “elevatorA”? … if there are two how does the button know which one it’s is working on?

Elevator_Floor_1 = Elevator A in my example. Those weren’t the literally names, but they are different.

Here is the second version:

1359776--67621--$elevatorscript2_zpsc481d05e.png

The problem is probably in your script, not the inspector.

Seems okay:

using UnityEngine;
using System.Collections;

public class ElevatorSwitch : MonoBehaviour {
	
	
	
	float speed = 1.0f;
	float speedSmoothing = 1.0f;
	public float flash;
	public float flashSmoothing;
	public float rotationSpeed;
	public Light elevatorStatusLight;
	
	public GameObject elevatorFloor;
	public GameObject statusLight;
	public GameObject cautionLight;
	
	public Color readyLight = new Color(0.0f, 1.0f, 0.0f, 1.0f);
	public Color waitLight = new Color(1.0f, 0.0f, 0.0f, 1.0f);
	//public Camera camera;
	
	private Vector3 upPosition; //new Vector3(25.5f, 4.40f, 20.8f);
	private Vector3 downPosition; // new Vector3(25.5f, 0.05f, 20.8f);
	private Vector3 newPosition;
	//private bool elevatorLockout = false;
	private bool elevatorPosition = false;
	//private float elevatorLockoutTime = 3.0f;
	private float lastButtonPressTime;
	private bool motorOn = false;
	RaycastHit hit;
	
	
	
	void Awake () {
		
		
		
		upPosition = elevatorFloor.transform.position;
		downPosition = new Vector3(elevatorFloor.transform.position.x, 0.05f, elevatorFloor.transform.position.z);
		//downPosition = new Vector3(upPosition.x, upPosition.y - 4.0f, upPosition.z);
		
		Debug.Log ("Adjusted Elevator Position: " + elevatorFloor.transform.position);
		
		elevatorStatusLight.light.color = Color.green;
		statusLight.renderer.material.color = Color.green;
		
		Debug.Log ("Elevator Status: " + elevatorPosition);
		
	}
	
	void Update () {
	
		//cautionLight.transform.Rotate(Vector3.right * Time.deltaTime * rotationSpeed);
		
		
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
				
		
		if(Input.GetMouseButton(0)  Physics.Raycast(ray, out hit, 1)){
			
			
			
			//	if(){		//transform.position, fwd, out hit, 10
			
					Debug.DrawLine(ray.origin, hit.point, Color.yellow);
					Debug.Log (hit.point);
			
			
					Debug.Log("You pushed the elevator button!");
					motorOn = true;
			}
	//	}
		
		if(motorOn == true){
			MoveElevator();
			}
			
		}
		
	
		
	void MoveElevator(){
			//Debug.Log ("Raycast: " + hit.collider.name);
			
				if(elevatorPosition == false){
					newPosition = Vector3.down;}
				if(elevatorPosition == true){
					newPosition = Vector3.up;}
	
				elevatorStatusLight.light.color = Color.Lerp (elevatorStatusLight.light.color, waitLight, flash * Time.deltaTime * flashSmoothing);
				statusLight.renderer.material.color = Color.Lerp(statusLight.renderer.material.color, Color.red, flash * Time.deltaTime * flashSmoothing);
				//elevatorFloor.transform.position = Vector3.Lerp (elevatorFloor.transform.position, newPosition, speed * Time.deltaTime * speedSmoothing);
				elevatorFloor.transform.Translate(newPosition * Time.deltaTime * speed);
				cautionLight.active = true;
				cautionLight.transform.Rotate(Vector3.right * Time.deltaTime * rotationSpeed);
				Debug.Log("Elevator is moving towards: " + elevatorPosition);
				Debug.Log("Elevator is at: " + elevatorFloor.transform.position);

					
					if(elevatorFloor.transform.position.y >= upPosition.y || elevatorFloor.transform.position.y <= downPosition.y){
						statusLight.renderer.material.color = Color.Lerp(statusLight.renderer.material.color, Color.green, flash * Time.deltaTime * flashSmoothing);
						elevatorStatusLight.light.color = Color.Lerp (elevatorStatusLight.color, readyLight, flash * Time.deltaTime * flashSmoothing);
						cautionLight.active = false;
						motorOn = false;
						Debug.Log("Elevator is Ready!");
						elevatorPosition = !elevatorPosition;
						
						}
				
				}
			
			}

This does not check what the player clicked, only that something was clicked. As such, all scripts are firing on each click.

It was my understanding that it only fired scripts attached to the hit object. You’re saying it fires every instance of the script in the scene, with their overrides?

More to the point, how would I get it to only look at it’s own scripts and ignore the others? I could make item tags, but that would just invalidate the overrides.

EDIT - I just went ahead and used tags. Looks like that method is not uncommon.

Update function is run on each game tick, regardless of anything that’s happening.

If you wanted it to just check that object, you could put a collider on it and the OnMouse functions, and that would only call the button that was clicked.

Alternatively, the raycast hit returns the object that was hit, and so you could compare it with the object that the script is attached to.