help i am new Assets/HealthPlayer.cs(19,30): error CS0266: Cannot implicitly convert type float' to
int’. An explicit conversion exists (are you missing a cast?)
updated new errors
i am trying to send message from ray cast HealthPlayer script
HealthPlayer code
using UnityEngine;
using System.Collections;
public class HealthPlayer : MonoBehaviour {
public int health = 100;
public bool dead = false;
// Use this for initialization
void Start () {
}
/*public static void ApplyDamage (float theDamage)
{
health -= theDamage;
}*/
// Update is called once per frame
public static void ApplyDamage( HealthPlayer healthPlayer, float theDamage ) {
healthPlayer.health -= theDamage;
}
void Update () {
if (health < 0)
dead = true;
if (dead) {
GetComponent<CharacterMotor>().enabled = false;
GetComponent<MouseLook>().enabled = false;
}
}
void OnControllerColliderHit(ControllerColliderHit collision)
{
//Debug.Log(string.Format("object tag={0}",collision.collider.gameObject.tag));
if (collision.gameObject.tag == "block") {
Debug.Log("working");
health -= 10;
}
}
}
RayCastShooting Code
using UnityEngine;
using System.Collections;
public class RayCastShooting : MonoBehaviour {
public GameObject Character;
private RaycastHit Hit;
public float theDamage;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 myTransform = Character.transform.forward;
if (Input.GetKey (KeyCode.Mouse0)) {
if(Physics.Raycast(transform.position , myTransform , out Hit , 20)){
if(Hit.collider.gameObject.CompareTag("block")){
Debug.DrawRay(transform.position , Character.transform.forward , Color.red);
print("objecktas debile");
//Hit.collider.gameObject.SendMessage("ApplyDamage", theDamage, SendMessageOptions.DontRequireReceiver);
HealthPlayer.ApplyDamage( HealthPlayer, 10 );
}
}
}
}
}