x


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.

more ▼

asked Sep 25 '11 at 04:55 AM

MySecretWeapon gravatar image

MySecretWeapon
1 3 3 4

How can 2 objects share a single meshrenderer or a particle emitter?

Sep 25 '11 at 05:15 AM Evil-Dog

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?

Sep 25 '11 at 03:40 PM msknapp

I think you'll need to define "won't work right" so we have a handle on what to look for...

Sep 25 '11 at 06:00 PM Bovine

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

Sep 25 '11 at 06:51 PM loopyllama
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5098
x4175
x3340
x2097
x1260

asked: Sep 25 '11 at 04:55 AM

Seen: 644 times

Last Updated: Sep 25 '11 at 07:22 PM