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 MATS_fj06 · Oct 10, 2021 at 02:14 PM · unity 5visual studiocodepagevoid

code in void not executing

can anyone help me plz? i've been trying to fix this problem for the past hour (i'm still fresh to c#) Basically i want to implement camera shake every time the enemy dies. I wrote the code for it in a public void alongside death effects and deletion of the gameobject. The weird thing is, when i kill the enemy through shooting, everything happens except the camera shake. i thought it was a code error but the weirder thing is that, when i kill the enemy through player-enemy collision (on contact death), the camera shake takes place. What's even weirder is that, btw I've written the enemy one first, I have the same exact one but for when the player dies, and it works. i'll write the code if anyone wants to check it

This one is for when the enemy dies

 public void DamageEnemy(int damage)
     {
         stats.currentHealth -= damage;
 
         if (stats.currentHealth <= 0)
         {
             GameMaster.KillEnemy(this);
             Debug.Log("Enemy Dead");
         }
 
         if (statusIndicator != null)
         {
             statusIndicator.SetHealth(stats.currentHealth, stats.maxHealth);
         }
     }

This one is to do whatever I want when the enemy dies (everything works except the camera shake)

 public static void KillEnemy(Enemy enemy)
     {
         gm._KillEnemy(enemy);
     }
 
     public void _KillEnemy(Enemy _enemy)
     {
         Destroy(_enemy.gameObject);
         GameObject _clone = Instantiate(_enemy.deathParticles.gameObject, _enemy.transform.position, Quaternion.identity) as GameObject;
         Destroy(_clone, 5f);
         cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
     }
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Rechronicle · Oct 10, 2021 at 02:53 PM

          Destroy(_enemy.gameObject);  // maybe because you destroy the enemy here?
          GameObject _clone = Instantiate(_enemy.deathParticles.gameObject, _enemy.transform.position, Quaternion.identity) as GameObject;
          Destroy(_clone, 5f);
          cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength); // then you try to call it here

If you use the exact same script for the player, it will work because you don't destroy the '_player' there.

Comment
Add comment · Show 3 · 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 MATS_fj06 · Oct 10, 2021 at 03:33 PM 0
Share

But the thing is, the enemy gameobject destroys, the particles appear, they are then deleted (the 5f), but the camera shake doesn't happen. Plus, why you'd it only shake when the enemy dies to collision with player and not when it dies to being shot? i don't have any code that specifies it because whether the enemy dies to collision or gun, they are referred to that exact void.

avatar image Rechronicle MATS_fj06 · Oct 10, 2021 at 03:46 PM 0
Share

Maybe try to put in debug right before the camera shake to see if the code runs or not? also, is there no console log error when you try to call it through shooting?

avatar image MATS_fj06 Rechronicle · Oct 10, 2021 at 03:50 PM 0
Share

I implemented a debug before ("start of shaking") and after the camera shake ("end of shaking"). They both appear in the console but no shake happens. There are no errors as well.

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

227 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

visual studio tools for unity not working 1 Answer

Instantiating an object only once within Update() 2 Answers

cannot add sliders or progressbar 1 Answer

if (Input.GetKeyDown("w")) Not working 1 Answer

How to let player know they have completed a level 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