- Home /
Pacman eating (destroying) pellets on collision!
We are trying to make our Pacman destroy pellets as he moves over them. We have this non-functional script so far. Any help would be appreciated!
using UnityEngine;
using System.Collections;
public class EatPellet : MonoBehaviour {
public int smallPellet = 10;
public int bigPellet = 100;
public int score = 0;
public int pelletCount = 0;
public void onTriggerEnter ()
{
if (GameObject.name == "smallPellet")
{
score += smallPellet;
pelletCount++;
Destroy(gameObject.name("smallPellet"));
}
else if (GameObject.name == "bigPellet")
{
score += bigPellet;
pelletCount++;
Destroy(gameObject.name("bigPellet"));
}
}
public string toString ()
{
string totalScore = "Score: ";
totalScore += score;
return totalScore;
}
public void changeScreen()
{
if (pelletCount == xx) {
Debug.Log("fullt");
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613135057im_/https://answers.unity.com/themes/thub/images/avi.jpg)