Error CS1519
On line 8,26 error CS1519 shows up.. here's the script for reference:
using UnityEngine; using System.Collections;
public class DestroyOnContact : MonoBehaviour {
public int count;
public GameObject;
public bool CompareTag (string tag);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Collision.gameObject.tag == other.gameObject.tag)
{
count+=1;
Collision.transform.parent = transform;
}
if(transform.childCount >= 2 && count>= 3)
{
Destroy(gameObject);
Destroy(other.Gameobject);
count = 1;
}
}
}
I don't understand how to fix it, due to the fact that I'm a beginner. Can someone show me how to fix this please?
Answer by Astraphobia95 · Jan 28, 2016 at 05:29 PM
public bool CompareTag (string tag);
is wrong, are you trying to write a function? What are you trying to do here? You need to delete this for the program to run.
Next, you're trying to access a Collision, but you haven't used a function to initialize the collision. Assuming you're using 3D objects you'll want to wrap
if(Collision.gameObject.tag == other.gameObject.tag)
{
count+=1;
Collision.transform.parent = transform;
}
In a collision function, most likely OnCollisionEnter. On the subject if this if statement, you're trying to access "other"' but you haven't created or initialized it anywhere, so you'll need to do that.
The part of your code that destroys the object should work fine once you fix those problems.
Your answer
Follow this Question
Related Questions
Soccer game, more realistic net 1 Answer
Detect overlapping objects 2D game 0 Answers