• 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 Echofiend 1 · Oct 29, 2010 at 12:14 AM · renderergameobjectsmeshrenderer

I cant turn off my mesh renderer for some reason

Hi Everyone,

I am having a problem turning my mesh off when my player dies. I have my networking going.. it is detecting collisions and triggering the explosion but I cant get it to turn off... here is what I have so far.

[RPC] public void KillThisPlayer() { myState = State.dead; gameObject.renderer.enabled = false; turret.gameObject.renderer.enabled = false; StartCoroutine(DestroyTank()); }

[RPC] public void TurnOffThisRenderer() { //MeshRenderer rendered = (MeshRenderer)gameObject.GetComponent("Tank").GetComponent("MeshRenderer");

 //MeshRenderer turret = gameObject.GetComponent("Turret").GetComponent<MeshRenderer>();

 //rendered.renderer.enabled = false;
 //turret.enabled = false;

 //These objects are declared as Transforms at class level and they are found and //used throughout the code
 turret.renderer.enabled = false;
 stvol.renderer.enabled = false;

}

IEnumerator DestroyTank() {

 Network.Instantiate(ExplosionPrefab, myTransform.position, Quaternion.identity,0);

 turret.renderer.enabled = false;

 GameObject[] spawnpoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
 Debug.Log("Spawns: " + spawnpoints.Length);

 Transform spawnPoint = spawnpoints[Random.Range(0, spawnpoints.Length)].transform;

 yield return new WaitForSeconds(respawnTime);
 myTransform.position = new Vector3(spawnPoint.position.x, 1, spawnPoint.position.z);
 gameObject.renderer.enabled = true;
 turret.renderer.enabled = true;
 myState = State.playing;
 myHealth = 100;

}

public void DecreaseHealth(int value) { //decrease it by the amount of damage the projectile does if (myState == State.dead || myState == State.invincible) return; if (Network.isClient) return; Debug.Log(Network.isServer ? "we are a server" : "we are a client"); myHealth -= value;

 if (myHealth <= 0)
 {
     Debug.Log(userName + " is dead");
     //Instantiate(ExplosionPrefab, myTransform.position, Quaternion.identity);
     networkView.RPC("TurnOffThisRenderer", RPCMode.AllBuffered, null);
     networkView.RPC("KillThisPlayer", RPCMode.All,null);
 }
 else
     Debug.Log(userName + " has " + myHealth + " health left.");

The coroutine and everything works fine even on the networked computers, as it finds the spawnpoint and respawns like it should.

I have tried many ways to get to the meshrenderer but it keeps saying it is nullreference. I just dont know how to get to it I suppose.

I have my prefab set up like this

  • Player
  • Tank (this is the tank body)
  • Turret (turret sits on top of the body)
  • Camera / text object.

I have ensured that the player object has a mesh renderer, the Tank and Turret object do as well. Anyone see anything wrong with what I am doing? or why it will not disappear on either the server or client?

Any help appreciated.

Mike

Comment
Add comment · Show 1
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 Echofiend · Oct 29, 2010 at 12:20 AM 0
Share

Sorry, the prefab explanation got a little weird with formatting.. the top level of the prefab is Player, then under those there are the other items (such as Tank, Turret)

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Jazzer008 · May 24, 2013 at 03:23 AM

 gameObject.GetComponent(MeshRenderer).enabled = false;

That might help.

Edit: Just noticed you asked the question over 2 years ago! You've probably already figured it out. :D Unless I just saved you from eternal damnation. :P

Comment
Add comment · Share
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
0

Answer by Zulu · Dec 28, 2010 at 12:39 AM

Did you try

transform.Find("turret").GetComponent("MeshRenderer").enabled = false;

Comment
Add comment · Share
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
0

Answer by Yanger_xy · Mar 13, 2011 at 11:20 AM

Of course, you can!

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Toggle Game Objects with specific tag at runtime 0 Answers

Count Objects with specific colour 1 Answer

Finding a specific layer's MeshRenderer 0 Answers

How to change a specific material of an object at runtime ? 2 Answers

Renderer.enable for GameObject[]? 3 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