Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Benji-John93 · May 15, 2013 at 09:56 AM · spawncharacter controllerrespawn

Character respawns invisable?

Hey everyone im new to unity and i have made an enemy, done some basic ai using rain, have gave him health and gave him a respawn, but when he dies he respawns but he is invisible, it seems as though only the "character controller" along with its sensors, mind ect. the actual models arent coming back? please help :/

Comment
Add comment · Show 2
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 ahaykal · May 15, 2013 at 11:05 AM 0
Share

You need to show us some code of the respawn script. We can't really help you like that... $$anonymous$$aybe its disabling the mesh renderer. maybe you have an error... lots of stuff could be happening..

avatar image s_guy · May 16, 2013 at 06:36 AM 0
Share

We don't have enough to go on. Pause the game after the enemy respawns and investigate.

  • What are you seeing that suggests he respawned at all?

  • Click on the enemy in the hierarchy. Does he have expected x, y, and z positions? $$anonymous$$aybe he isn't in your camera frustum?

  • Is the enemy's mesh present? Did you manipulate the mesh?

  • Any chance you moved a child object and not the parent, or maybe you moved the parent, but the child containing the mesh was displaced?

  • Is there anything that you're doing on the initial spawn to make the character appear as expected, that you're not doing on respawn?

This is a very open ended question. You'll need to provide more information. Good luck!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benji-John93 · May 21, 2013 at 12:08 AM

///////////////////////////////////////////////////////////////////////////////// // // vp_DamageHandler.cs // © 2012 VisionPunk, Minea Softworks. All Rights Reserved. // // description: class for having a gameobject take damage, die and respawn. // any other object can do damage on this monobehaviour like so: // hitObject.SendMessage(Damage, 1.0f, SendMessageOptions.DontRequireReceiver); // /////////////////////////////////////////////////////////////////////////////////

using UnityEngine;

public class vp_DamageHandler : MonoBehaviour {

 // health and death
 public float Health = 10.0f;            // initial health of the object instance, to be reset on respawn
 public GameObject DeathEffect = null;    // gameobject to spawn when object dies.
                                             // TIP: could be fx, could also be rigidbody rubble
 public float MinDeathDelay = 0.0f;        // random timespan in seconds to delay death. good for cool serial explosions
 public float MaxDeathDelay = 0.0f;
 protected float m_CurrentHealth = 0.0f;    // current health of the object instance

 // respawn
 public bool Respawns = true;            // whether to respawn object or just delete it
 public float MinRespawnTime = 3.0f;        // random timespan in seconds to delay respawn
 public float MaxRespawnTime = 3.0f;
 public float RespawnCheckRadius = 1.0f;    // area around object which must be clear of other objects before respawn
 public AudioClip RespawnSound = null;    // sound to play upon respawn
 protected Vector3 m_StartPosition = Vector3.zero;                // initial position detected and used for respawn
 protected Quaternion m_StartRotation = Quaternion.identity;        // initial rotation detected and used for respawn
 

 ///////////////////////////////////////////////////////////
 // 
 ///////////////////////////////////////////////////////////
 void Awake()
 {

     m_CurrentHealth = Health;
     m_StartPosition = transform.position;
     m_StartRotation = transform.rotation;

 }


 ///////////////////////////////////////////////////////////
 // reduces current health by 'damage' points and kills the
 // object if health runs out
 ///////////////////////////////////////////////////////////
 public void Damage(float damage)
 {

     if (!enabled || !gameObject.active)
         return;

     m_CurrentHealth -= damage;

     if (m_CurrentHealth <= 0.0f)
     {
         // TIP: if you want to display an effect on the object just
         // before it dies - such as putting a crack in an armor the
         // second before it shatters - this is the place
         vp_Timer.In(Random.Range(MinDeathDelay, MaxDeathDelay), Die);
         return;
     }

     // TIP: if you want to do things like play a special impact
     // sound upon every hit (but only if the object survives)
     // this is the place

 }


 ///////////////////////////////////////////////////////////
 // removes the object, plays the death effect and schedules
 // a respawn if enabled, otherwise destroys the object
 ///////////////////////////////////////////////////////////
 public void Die()
 {

     if (!enabled || !gameObject.active)
         return;

         RemoveBulletHoles();
         gameObject.SetActiveRecursively(false);

         if (DeathEffect != null)
             Object.Instantiate(DeathEffect, transform.position, transform.rotation);

         if (Respawns)
             vp_Timer.In(Random.Range(MinRespawnTime, MaxRespawnTime), Respawn);
         else
             Object.Destroy(gameObject);
     
 }


 ///////////////////////////////////////////////////////////
 // respawns the object if no other object is occupying the
 // respawn area. otherwise reschedules respawning
 ///////////////////////////////////////////////////////////
 protected void Respawn()
 {

     // return if the object has been destroyed (for example
     // as a result of loading a new level while it was gone)
     if (this == null)
         return;

     // don't respawn if player is within checkradius
     // TIP: this can be expanded upon to check for additional object layers
     if (Physics.CheckSphere(m_StartPosition, RespawnCheckRadius, ((1 << vp_Layer.Player) | (1 << vp_Layer.Props))))
     {
         // attempt to respawn again until the checkradius is clear
         vp_Timer.In(Random.Range(MinRespawnTime, MaxRespawnTime), Respawn);
         return;
     }

     // reset health, position, angle and motion
     m_CurrentHealth = Health;
     transform.position = m_StartPosition;
     transform.rotation = m_StartRotation;
     if (rigidbody != null)
     {
         rigidbody.angularVelocity = Vector3.zero;
         rigidbody.velocity = Vector3.zero;
     }

     // reactivate object and play spawn sound
     gameObject.active = true;
     if (audio != null)
         audio.PlayOneShot(RespawnSound);
     
 }


 ///////////////////////////////////////////////////////////
 // removes any bullet decals currently childed to this object
 ///////////////////////////////////////////////////////////
 protected void RemoveBulletHoles()
 {

     foreach (Transform t in transform)
     {
         Component[] c;
         c = t.GetComponents();
         if (c.Length != 0)
             Object.Destroy(t.gameObject);
     }

 }
 

}

Heres the code im using, the parent respawns but the children do not :( (script is c#)

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.

Follow this Question

Answers Answers and Comments

14 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Can't set timer 1 Answer

SendMessage setName has no receiver! 1 Answer

How to spawn objects in a specific range of random location 1 Answer

How to assign transfrom array in the code? 1 Answer


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