Trying to get collider object name,Trying to get colliding object name
So I'm making 4X game base for a uni hw project and I'm trying to get the colliding object name so I can use the FindResources method that is on another script to add the specific name to a list and add the gold and food to the base terrain tile text panel and I made it so its someway detecting the resource (pollution) but its also detecting itself (button) and its not entering the FindResource method I'm a newbie at this and idk whats happening pls help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CollissionGetter : MonoBehaviour
{
public ChangeText ChangeTextScript;
public Collider buttomColider;
public Collision colliding;
public string collidingResources;
// Start is called before the first frame update
void Start()
{
ChangeTextScript = FindObjectOfType<ChangeText>();
buttomColider = GetComponent<BoxCollider>();
//colliding = buttomColider.GetComponents();
//Debug.Log(buttomColider.OnCollissionEnter());
OnCollisionEnter(colliding);
}
void OnCollisionEnter(Collision collision)
{
int n = 0;
foreach (ContactPoint contact in collision.contacts)
{
n++;
//collidingResources = contact.thisCollider.name;
collidingResources = collision.gameObject.ToString();
Debug.Log(collidingResources);
ChangeTextScript.FindResources(collidingResources);
}
Debug.Log(n);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613045918im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I have two different objects I would like to check when A and B gameObjects are collided ? 1 Answer
cant pause game when character collides,cant pause when my character dies 1 Answer
Why Character is going through the floor. 0 Answers
Team Pong Colliders not working 0 Answers
Absolutely no collision detection in build but editor is fine 1 Answer