I have a collider that makes your score go up each time you hit one but I don’t want to be able to go back and forth and keep getting easy points. How do I disable the collider so I don’t score more than 1 point for each object I pass through?
I would use 2 scripts for this, one attached to the “enemy” or whatever you are "hitting and one attached to the player (I’ve called it bullet but use what you want) this method allows different enemies or objects to share the same script but affect the score in different ways
using UnityEngine;
using System.Collections;
public class enemy : MonoBehaviour {
// Use this for initialization
public bool hit = false;
public int points = 10;
void Start () {
}
// Update is called once per frame
void Update () {
}
}
and the player/bullet script
using UnityEngine;
using System.Collections;
public class bullet : MonoBehaviour {
// Use this for initialization
int Score = 0;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision collision)
{
if(collision.transform.tag == "enemy")
{
enemy enemyScript = collision.transform.GetComponent<enemy>();
if(!enemyScript.hit)
{
Score += enemyScript.points;
enemyScript.hit = true;
}
}
}
}