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 /
avatar image
0
Question by Yonisit · Sep 20, 2019 at 02:01 PM · c#unity 5databaserpgmonster

A real head-scratcher

I am trying to get health of a monster at the start, and it works absolutly fine, but when I see in the inspector I see "0" health. in the start it works fine, it shows the right health "200", but a second later it shows in inspector of the monster + in the console that the health is "0". so at the start the monster script should get the health (int) from another script. l hope you can find out what's wrong, because trust me I am good at coding but im trying to figure out over 2 days what's wrong. Thanks a lot for even reading this! I've tried EVERYTHING I CAN, I get the health from the database correctly, but it wont work, after the start the "StartingHealth" just resets to "0" IDK why :( please help, thanks! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ using System.Collections; using System.Collections.Generic; using UnityEngine;

     public class MonsterData : MonoBehaviour
     {
     public int MonHealth;
     public string[] items;
     private string MonsterDataLink = "https://classeskingdom.000webhostapp.com/SetMonster.php";
     private string MonsterGetDataLink = "https://classeskingdom.000webhostapp.com/GetMonsterData.php";
     [SerializeField] private string MonsterName;
     [SerializeField] private int Health,Exp, RunesMin, RunesMax, Item,Item1,Item2,Item3,Item4,Item5,Item6,Item7,Level,DEF,Attack;
     [SerializeField] private int MonsterID;

     private void Start()
     {
     //StartCoroutine(GetMonsterData(MonsterID));
     //StartCoroutine(CreateMonster(MonsterName,Health, Exp, RunesMin,RunesMax, Item, Item1, Item2, Item3, Item4, Item5, Item6, Item7,Level,DEF,Attack));
     }

     IEnumerator CreateMonster(string MonsterName,int Health,int Exp,int RunesMin,int RunesMax,int Item,int Item1,int Item2,int Item3,int Item4,int Item5,int Item6,int Item7,int Level,int DEF, int Attack)
 {
     WWWForm MonsterRegister = new WWWForm();
     MonsterRegister.AddField("NamePost", MonsterName);
     MonsterRegister.AddField("HealthPost", Health);
     MonsterRegister.AddField("ExpPost", Exp);
     MonsterRegister.AddField("RunesMinPost", RunesMin);
     MonsterRegister.AddField("RunesMaxPost", RunesMax);
     MonsterRegister.AddField("ItemPost", Item);
     MonsterRegister.AddField("Item1Post", Item1);
     MonsterRegister.AddField("Item2Post", Item2);
     MonsterRegister.AddField("Item3Post", Item3);
     MonsterRegister.AddField("Item4Post", Item4);
     MonsterRegister.AddField("Item5Post", Item5);
     MonsterRegister.AddField("Item6Post", Item6);
     MonsterRegister.AddField("Item7Post", Item7);
     MonsterRegister.AddField("LevelPost", Level);
     MonsterRegister.AddField("DEFPost", DEF);
     MonsterRegister.AddField("AttackPost", Attack);
     WWW wwwRegister = new WWW(MonsterDataLink, MonsterRegister);
     yield return wwwRegister;
     Debug.Log(wwwRegister.text);
 }
     public IEnumerator GetMonsterData(int MonsterID)
     {
     WWWForm MonsterGetData = new WWWForm();
     MonsterGetData.AddField("MonsterIDPost", MonsterID);
     WWW wwwMonsterData = new WWW(MonsterGetDataLink, MonsterGetData);
     yield return wwwMonsterData;
     string MonsterDataString = wwwMonsterData.text;
     items = MonsterDataString.Split(';');
     string Data = (GetDataValue(items[MonsterID - 1], "Health:"));
     yield return Data;
     Debug.Log(Data);
     GetInfo(Data);
     }
     public string GetDataValue(string data, string index)
     {
     string value = data.Substring(data.IndexOf(index) + index.Length);
     value = value.Remove(value.IndexOf("|"));
     return value;
     }
     private void GetInfo(string health)
     {
     int sethealth = int.Parse(health);
     MonsterMove mons = new MonsterMove();
     Debug.Log(sethealth);
     mons.SetHealth(sethealth);
     }
     }

//MONSTER CODE: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

         public class MonsterMove : MonoBehaviour
         {
         #region //start
         public int StartingHealth;
         private int starts;
         [SerializeField] private int MonsterID=1;
         public Animator anim;
         public bool IdleAnimBool = false;
         public bool PatrolAnimBool = true;
         [SerializeField]
         private float TimeCounterStartPatrol,FixedPatrolTime;
         private float RandomTimePatrol, TimeCounterBasePatrol;
         [SerializeField]
         private float TimeCounterStartIdle,FixedIdleTime;
         private float RandomIdleTime, TimeCounterBaseIdle;
         [SerializeField]
         private bool ShouldBeIdle=false;
         public float MonsterMoveSpeed;
         public float Distance=2f;
         [SerializeField]
         private bool ShouldBePatroling = true;
         private bool MovingRight = true;
         public Transform groundDetection;
 #endregion 
     private void Start()
     {
         MonsterData mons = new MonsterData();
         StartCoroutine(mons.GetMonsterData(MonsterID));
         MonsterMoveSpeed = Random.Range(1, 1.3f);
         TimeCounterBasePatrol = TimeCounterStartPatrol;
         TimeCounterBaseIdle = TimeCounterStartIdle;
         RandomTimePatrol = Random.Range(0f, TimeCounterStartPatrol-FixedPatrolTime);
         RandomIdleTime = Random.Range(0f, TimeCounterStartIdle-FixedIdleTime);
     }
     void FixedUpdate()
     {
         Debug.Log(StartingHealth);
         if (ShouldBePatroling&&!ShouldBeIdle)
         {
             Move();
             PatrolTime();
             PatrolAnim();
             anim.SetBool("run", true);
             anim.SetBool("idle", false);
         }
         if (ShouldBeIdle==true&&!ShouldBePatroling) {
             IdleAnim();
             IdleTime();
             anim.SetBool("run", false);
             anim.SetBool("idle", true);
         }
     }
     void Move()
     {
         transform.Translate(Vector2.right * MonsterMoveSpeed * Time.deltaTime);
         int layer_mask1 = LayerMask.GetMask("Ground");
         RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, Distance, layer_mask1);
         if (groundInfo.collider == false)
         {
             if (MovingRight == true)
             {
                 transform.eulerAngles = new Vector3(0, -180, 0);
                 MovingRight = false;
             }
             else
             {
                 transform.eulerAngles = new Vector3(0, 0, 0);
                 MovingRight = true;
             }
         }
     }
     private void PatrolTime()
     {
         TimeCounterStartPatrol -= Time.fixedDeltaTime;
         if (TimeCounterStartPatrol <= RandomTimePatrol)
         {
             ShouldBePatroling = !ShouldBePatroling;
             ShouldBeIdle = !ShouldBeIdle;
             TimeCounterStartPatrol = TimeCounterBasePatrol;
         }
     }
     private void IdleTime()
     {
         TimeCounterStartIdle -= Time.fixedDeltaTime;
         if (TimeCounterStartIdle <= RandomIdleTime)
         {
             ShouldBePatroling = !ShouldBePatroling;
             ShouldBeIdle = !ShouldBeIdle;
             TimeCounterStartIdle = TimeCounterBaseIdle;
         }
     }
     private void IdleAnim()
     {
         if (IdleAnimBool == true && PatrolAnimBool == false)
         {
             IdleAnimBool = false;
             PatrolAnimBool = true;
         }
     }
     private void PatrolAnim()
     {
         if (PatrolAnimBool == true && IdleAnimBool == false)
         {
             PatrolAnimBool = false;
             IdleAnimBool = true;
         }
     }
     private void ChangeAnim()
     {

     }
     public void SetHealth(int health)
     {
         StartingHealth = health;
     }
     }
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

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

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

Bool condition is always resulting in false even when it seems impossible to be false even using debug lines to check 4 Answers

Unity - database for keeping score? 1 Answer

Saving & Optimizing a scene with ten thousand prefabs in a Server Client environment 0 Answers

Remote database for leaderboard 2 Answers

Monster AI patrol an idle 0 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