Whenever I try to add this code into my player for my Space Invaders game this error show up, the code I’m trying to do is add a score to my player for every time one of my objects collide with the Alien.
Assets/Scripts/Player.cs(6,25): error CS0031: Constant value 0' cannot be converted to a
int’
This is my code for my player
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public int Score = 0f;
CharacterController cc;
public float Speed = 5f;
// Use this for initialization
void Start()
{
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
float xinput = Input.GetAxis("Horizontal") * Speed;
cc.Move(new Vector3(xinput * Time.deltaTime, 0, 0));
}
void Collected()
{
Score++;
}
}
And this is my collectable code (or alien)
using UnityEngine;
using System.Collections;
public class Collectable : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
other.SendMessage("Collected");
Destroy(gameObject);
}
}
Usually this normally works but I can’t get it to work now.