Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MySecretWeapon · Sep 25, 2011 at 04:55 AM · c#gameobjectprefab

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Evil-Dog · Sep 25, 2011 at 05:15 AM 0
Share

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

avatar image msknapp · Sep 25, 2011 at 03:40 PM 0
Share

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?

avatar image Bovine · Sep 25, 2011 at 06:00 PM 0
Share

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

avatar image loopyllama · Sep 25, 2011 at 06:51 PM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# GetComponent Issue 2 Answers

Refering to gameobject script is attached to 1 Answer

How to create GameObject without adding it to scene? 1 Answer

Acessing scripts in other game objects with prefabs, without using GameObject.Find 1 Answer

Using script's method from all of the gameobjects that has that script 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges