Question by
kenkenkon · Jul 27, 2016 at 11:36 PM ·
collisiongameobjectsdetect
How do I make OnCollisionEnter if a GameObject collide other.
I am making a dodgeball game, and I am programming to when the ball touches someone, one point is added to the opponent; Then I started programming to when the ball collides an enemy, something happens, but the script I'm programming is applied to the player, and not the enemy. So can someone help me? My actual code:
UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class pointCounter : MonoBehaviour {
private int Bat_1_Score = 0;
private int Bat_2_Score = 0;
public Text Scoreboard;
public GameObject Bola;
void Start () {
Bola = GameObject.Find ("Bola");
}
void Update () {
}
//If ball collides the player
void OnCollisionEnter(Collision collision){
if(collision.gameObject.name == "Bola"){
Bat_2_Score++;
}
//If ball collides the opponent
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612085645im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
collider that OnControllerColliderHit detects but doesnt effect the characters position? 1 Answer
issues with other.gameObject.SetActive(false); 1 Answer
Why can I not pick up my moving/wandering objects yet I can pick up those that stay in one place? 0 Answers
(C#/OOP) Accessing one public function belonging to multiple gameObjects? 2 Answers
Script in C sharp collision when entered fires arrows at player 0 Answers