- Home /
Error In C#
Hello.
can someone help me? cause i wrote a script in c# This is the script:
using UnityEngine;
using System.Collections;
public class BulletInfo : MonoBehaviour {
public float BulletDestroy = 1.0f;
public float BulletDamage = 10;
public GameObject Target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Destroy(gameObject, BulletDestroy);
}
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Enemy"))
Target.GetComponent<EnemyHealth>().curHealth -=BulletDamage;
}
}
But now i got an error:
Error CS0266 Cannot implicity convert type float to int an explicit conversion exist (Are you missing a cast?)
Answer by meat5000 · Oct 26, 2013 at 11:53 AM
public float BulletDamage = 10;
->
public float BulletDamage = 10.0f;
Target.GetComponent<EnemyHealth>().curHealth -=BulletDamage1;
try
Target.GetComponent().curHealth -= (int)BulletDamage1;
assuming curHealth is an int
Thank you for answering!
But i changed it to this
using UnityEngine;
using System.Collections;
public class BulletInfo : $$anonymous$$onoBehaviour {
public float BulletDestroy = 1.0f;
public float BulletDamage1 = 10.0f;
public GameObject Target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Destroy(gameObject, BulletDestroy);
}
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Enemy"))
Target.GetComponent<EnemyHealth>().curHealth -=BulletDamage1;
}
}
But i still get the same error.
Please accept the answer if it solved your problem :) You may want to note that a parse from float to int will Always Round Down
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System. 0 Answers
Multiple Cars not working 1 Answer
not all lines of code running c# 0 Answers