- Home /
Two exact objects behaving differently... *scratches head*
I have two objects, one a duplicate of the other. They're campfires, and when you click on one it equips a temporary torch into your off hand. The problem is, one of them works fine, but the other one (which is a copy (same script, same variables, etc(literally, duplicated))) won't work right. There's nothing different about the two that I can tell at all. One simply works and the other doesn't. Is there any reason for this?
Here's the script if it helps at all:
using UnityEngine;
using System.Collections;
public class GetTorch : MonoBehaviour {
public MeshRenderer torch;
public ParticleRenderer flame;
public Light light;
public bool hasTorch;
public bool burnOutTimer;
private Transform _myTransform;
public float maxDistance = 4;
public float burnOut = 0;
public float maxBurn = 120;
// Use this for initialization
void Start () {
_myTransform = transform;
if(torch == null)
Debug.Log("");
if(flame == null)
Debug.Log("");
if(light == null)
Debug.Log("");
torch.enabled = false;
flame.enabled = false;
light.enabled = false;
hasTorch = false;
burnOutTimer = false;
burnOut = 0;
}
// Update is called once per frame
void Update () {
HasTorch();
BurnOut();
}
public void HasTorch(){
if(!hasTorch){
torch.enabled= false;
flame.enabled = false;
light.enabled = false;
burnOutTimer = false;
}
if(hasTorch){
torch.enabled= true;
flame.enabled = true;
light.enabled = true;
burnOutTimer = true;
}
}
public void BurnOut(){
if(burnOutTimer){
burnOut += Time.deltaTime;
}
if(burnOut > maxBurn){
burnOut = 0;
burnOutTimer = false;
hasTorch = false;
}
}
public void OnMouseUp(){
GameObject go = GameObject.FindGameObjectWithTag("Player");
if(go == null)
return;
if(Vector3.Distance(_myTransform.position, go.transform.position) < maxDistance){
hasTorch = true;
Messenger.Broadcast("HasTorch");
}
}
}
All the public variables are set on each one, like I said, everything is exactly the same, it's from the same dang prefab...
Help!?
EDIT:
Ok, sorry. To be more detailed, when you go over to the 'working' campfire and click on it, it activates your torch mesh (which burns out in 180 seconds and deactivates). When you walk over to the 'non working' campfire and click on it, the timers run and other boolean variables activate, but the torch mesh (and light and particle system) don't activate.
Everything looks like it should be working, but it doesn't.
How can 2 objects share a single meshrenderer or a particle emitter?
have you paused the game and looked at the two objects in inspector view? do they appear the same even in inspector view at runtime?
I think you'll need to define "won't work right" so we have a handle on what to look for...
I bet you hit command d to make the copy rather than drag in a new instance of the prefab. try deleting the broken one and drag in the prefab in your scene