Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by zimmer550 · Feb 08, 2017 at 07:52 PM · unity 5functions

My function is being called even when it shouldn't

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class GameController : MonoBehaviour { public GameObject enemy; public float setEnemyLinearSpeed; public float setEnemySideSpeed; public float setEnemyFollowSpeed; public float setEnemyJumpForce; public float setEnemyJumpFrequency; public float setEnemyShootFrequency; public float setHighestPointOfJump; public float setDownfallRate; public float setEnemyHealth; public float enemySpawnFrequency;

 private int decidingNumber;

 void Start() {
     RevertPrefabValuesToNormal ();
     print ("setting everything to normal");
     InvokeRepeating ("DecideWhatEnemyToSpawn", 1f, enemySpawnFrequency);
 }

 void DecideWhatEnemyToSpawn() {

// decidingNumber = Random.Range (0, 5); decidingNumber = 0; SetDefaultProperties (setEnemyLinearSpeed, setEnemyHealth);

     switch (decidingNumber) {
     case 0:
         print ("case 0");
         break;

     case 1:
         print ("case 1");
         SetSideSpeed (setEnemySideSpeed, true);
         break;

     case 2:
         print ("case 2");
         JumpParameters (setEnemyJumpForce, setEnemyJumpFrequency, setHighestPointOfJump, setDownfallRate, true);
         break;

     case 3:
         print ("case 3");
         SetFollowSpeed (setEnemyFollowSpeed, true);
         break;

     case 4:
         print ("case 4");
         EnemyShootFrequency (setEnemyShootFrequency, true);
         break;
     }
     Instantiate(enemy, new Vector3(transform.position.x, transform.position.y, Random.Range(15f, 38f)), transform.rotation);
     RevertPrefabValuesToNormal ();
     print ("everything should be back to normal again");
 }

 void RevertPrefabValuesToNormal() {
     SetDefaultProperties (0, 0);
     SetSideSpeed (0, false);
     SetFollowSpeed (0, false);
     JumpParameters (0, 0, 0, 0, false);
     EnemyShootFrequency (0, false);
     print("everything is normal now");
 }

 void SetDefaultProperties(float _setEnemyLinearSpeed, float _setEnemyHealth) {
     enemy.GetComponent<EnemyController> ().linearSpeed = _setEnemyLinearSpeed;
     enemy.GetComponent<EnemyController> ().health = _setEnemyHealth;
     print ("setting default");
 }

 void SetSideSpeed(float _setEnemySideSpeed, bool _canGoSide) {
     enemy.GetComponent<EnemyController> ().sideSpeed = _setEnemySideSpeed;
     enemy.GetComponent<EnemyController> ().canGoSide = _canGoSide;
 }

 void SetFollowSpeed(float _setEnemyFollowSpeed, bool _canFollow) {
     enemy.GetComponent<EnemyController> ().followSpeed = _setEnemyFollowSpeed;
     enemy.GetComponent<EnemyController> ().canFollow = _canFollow;
 }

 void JumpParameters(float _setEnemyJumpForce, float _setEnemyJumpFrequency, float _setHighestPointOfJump, float _setDownfallRate, bool _canJump) {
     enemy.GetComponent<EnemyController> ().jumpForce = setEnemyJumpForce;
     enemy.GetComponent<EnemyController> ().jumpFrequency = setEnemyJumpFrequency;
     enemy.GetComponent<EnemyController> ().highestPointOfJump = setHighestPointOfJump;
     enemy.GetComponent<EnemyController> ().downwardFallRate = setDownfallRate;
     enemy.GetComponent<EnemyController> ().canJump = true;
     print ("assigning jump");
 }

 void EnemyShootFrequency(float _setEnemyShootFrequency, bool _canShoot) {
     enemy.GetComponent<EnemyController> ().shootFrequency = setEnemyShootFrequency;
     enemy.GetComponent<EnemyController> ().canShoot = true;
     print ("assigning shoot");
 }

}

As you can clearly see, the SetJumpParameters() and SetEnemyShootFrequency() is being called even when they shouldn't be. Why is that?

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 KevRev · Apr 27, 2019 at 09:21 AM 0
Share

Sorry the code is messy and not very easy to read, so it's not clear what you are having problems with exactly? Can you edit the post to display the code properly?

You say we can clearly see that setjumpparameters() and setenemyshootfrequency() is being called, but the setjumpparameters method isn't referenced anywhere in the above code, and the setenemyshootfrequency only seems to be referenced as a variable that must be modified elsewhere, because I can't see where it has been set? If you can include all relevant code, format it so it's easy to read, and be clear on what is happening, what you expect to happen, and what you have tried so far, somebody may be able to help.
The guys able to offer their time and assistance don't want to sit debugging pages and pages of somebody else's code, so you'll likely get a much quicker response if you clarify the details as suggested above. I hope that helps.

avatar image Orion_Flame204 · Apr 27, 2019 at 05:17 PM 0
Share

Have you found the answer to this? If you have please tell me I am having the same problem. I can't post the code because it is private, but it is similar to yours. If I find the answer I will tell you if you don't know the answer already.

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

135 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

Related Questions

Call function of a MonoBehaviour class in another class 0 Answers

Using variables without overflow 0 Answers

Augmented reality possible functions? 0 Answers

Calling Function from another script not working 1 Answer

Method Group 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