- Home /
whats wrong with my code ???
can any one tell me whats wrong with my code
code:
 using UnityEngine;
 using System.Collections;
 
 public class tawfe2health : MonoBehaviour {
         public int maxHealth = 100;
         public int curHealth = 100;
        
         public float healthBarLength;
 
         // Use this for initialization
         void Start () {
                 healthBarLength = Screen.width / 2;
         
         
         }
        
         // Update is called once per frame
         void Update () {
                 AddjustCurrentHealth(0);
         if(curHealth == 0){
         transform.Position = new Vector3(13.70886, 0.5421925, 3.211538);
         }
         }
         
         void OnGUI() {
                 
                 GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
         }
        
         public void AddjustCurrentHealth(int adj) {
                 curHealth += adj;
                
                 if(curHealth < 0)
                         curHealth = 0;
                
                 if(curHealth > maxHealth)
                         curHealth = maxHealth;
                
                 if(maxHealth < 1)
                         maxHealth = 1;
                
                 healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
         
     }
 }
 
 
errors i am getting
1-Assets/Standard Assets/player/tawfe2health.cs(22,72): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments
2-ssets/Standard Assets/player/tawfe2health.cs(22,72): error CS1503: Argument `#1' cannot convert `double' expression to type `float'
3-Assets/Standard Assets/player/tawfe2health.cs(22,19): error CS1061: Type `UnityEngine.Transform' does not contain a definition for `Position' and no extension method `Position' of type `UnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?)
thanks in advance
Answer by whydoidoit · Sep 10, 2012 at 03:17 AM
It's transform.position (not .Position). When you create your vector you need an f after the numbers. 13.70886f etc
Yeap this solved my problem! I moved to C# from Javascript and forgot about the 'f' behind floats! Thanks!
Answer by Sundar · Sep 09, 2012 at 04:46 PM
Try this
 // Update is called once per frame
         void Update () {
                 AddjustCurrentHealth(0);
        if(curHealth == 0){
         transform.Position = new Vector3(13.70886f, 0.5421925f, 3.211538f);
         }
         }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                