When my game in unity starts, my character collides with objects it isn't touching

Viewed 31
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickup : MonoBehaviour
{
    public GameObject _Pickaxe;
    // Start is called before the first frame update
    void Start()
    {
     _Pickaxe = GameObject.Find("Pickaxe");
    }
    // Update is called once per frame
     
    void Update()
    {
   
   
    }
    void DestroyGameObject()
    {
        Destroy(gameObject);
    }
    
    

private void OnTriggerEnter(Collider collision)
    {
        Debug.Log("Collided with +" + collision.gameObject.name);
            if(collision.gameObject.name == "Pickaxe" );
        {
        Debug.Log("Touched pick");  
        }
       
    }
}   



In my script it logs whatever the character touches. In my scene i have a object placed about 10m away from where the player capsule spawns, somehow it collides with it before you can even move.

1 Answers

Your code have an error. It logs "Touched pick" for every collision. To fix it, your should remove the semicolon in this line if(collision.gameObject.name == "Pickaxe" );

Related