Help with coin pick up script
Im new to unity and making scripts. Im trying to make a script to pick up my coins but I keep getting 3 errors that i cant seem to fix. here are the errors:
error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
error CS1502: The best overloaded method match for UnityEngine.Object.Destroy(UnityEngine.Object)' has some invalid arguments error CS1503: Argument
#1' cannot convert object' expression to type
UnityEngine.Object'
and here is my code for the coins
using UnityEngine;
using System.Collections;
public class CoinPickup : MonoBehaviour {
public int pointsToAdd;
void onTriggerEnter2D (Collider2D other)
{
if (other.name == "Character") {
ScoreManager.AddPoints (pointsToAdd);
Destroy (GameObject);
}
}
}
Answer by joemane22 · Nov 15, 2015 at 09:24 PM
In the line Destroy(GameObject) you are trying to destroy the class GameObject instead of a variable just change that to Destroy(gameObject);
Also, I am not sure if ScoreManager.AddPoints is a static method or not, if it is not then you will need to create a variable for the ScoreMananger in the script and drop in the score manager object inside unity editors inspector.
Your answer
Follow this Question
Related Questions
Collecting items 1 Answer
Character shop 1 Answer
Rigidbody.addforce after scene reload 1 Answer
Add 2D Skeleton to the Scene if Button was pressed 0 Answers
Setup an animation script, but now mouselook is not working? 0 Answers