Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity Collision Doesnt work

Discussion in 'Physics' started by vincekieft, Dec 14, 2014.

  1. vincekieft

    vincekieft

    Joined:
    May 18, 2013
    Posts:
    54
    Hello everybody,

    I am making a MOBA game and i have some skills. but the collision detection on the skills wont work.
    The skill haves this code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Skull_Skill_01_Script : MonoBehaviour {
    5.  
    6.     public int CoolDownTime;
    7.     public int Demage;
    8.     public GameObject Parent;
    9.     public GameObject ColliderFolower;
    10.     public GameObject[] ExploDestoy;
    11.     public Transform SpawnPos;
    12.  
    13.     void Start (){
    14.         //GameObject ColliderFollower = Instantiate (ColliderFolower, this.gameObject.transform.position, this.gameObject.transform.rotation) as GameObject;
    15.         //ColliderFollower.GetComponent<Skill_Collider_Animated> ().SkillObjectTrans = this.gameObject.transform;
    16.         //ColliderFollower.GetComponent<Attack_Demage> ().Demage = 500;
    17.     }
    18.  
    19.     void Update (){
    20.         transform.Translate(Vector3.forward * 25 * Time.deltaTime);
    21.     }
    22.  
    23.     public void DestroySkill(){
    24.         GameObject Explo = Instantiate (ExploDestoy[0], SpawnPos.position, this.gameObject.transform.rotation) as GameObject;
    25.         Explo.gameObject.GetComponent<ParticleEmitter> ().Emit ();
    26.         GameObject Explo2 = Instantiate (ExploDestoy[1], SpawnPos.position, ExploDestoy[1].transform.rotation) as GameObject;
    27.         Explo2.gameObject.GetComponent<ParticleEmitter> ().Emit ();
    28.         Destroy (this.gameObject);
    29.     }
    30.  
    31.     public void ExtraEffect (){
    32.         GameObject Explo = Instantiate (ExploDestoy[0], SpawnPos.position, this.gameObject.transform.rotation) as GameObject;
    33.         Explo.gameObject.GetComponent<ParticleEmitter> ().Emit ();
    34.     }
    35. }
    36.  
    the skills has: Sphere Collider, Rigidbody (non-kinematic)

    The character that sould detect the Collision has: Character Controller, Rigidbody.
    and this code for collision Detections:
    Code (CSharp):
    1. public void OnCollisionEnter(Collision col){
    2.         print ("Name is" + col.gameObject.name.ToString());
    3.         if (this.gameObject.tag == "Player_Team1") {
    4.             if(col.gameObject.tag == "Team2Attack" && this.gameObject.GetPhotonView().isMine){
    5.                 int DemageDone = col.gameObject.GetComponent<Attack_Demage>().Demage;
    6.                 this.gameObject.GetPhotonView().RPC("HitByEnemy", PhotonTargets.AllViaServer, DemageDone);
    7.                 print("This is " + col.gameObject.name);
    8.             }
    9.                 } else {
    10.             if(col.gameObject.tag == "Team1Attack"  && this.gameObject.GetPhotonView().isMine){
    11.                 int DemageDone = col.gameObject.GetComponent<Attack_Demage>().Demage;
    12.                 this.gameObject.GetPhotonView().RPC("HitByEnemy", PhotonTargets.AllViaServer, DemageDone);
    13.                 print("This is " + col.gameObject.name);
    14.             }
    15.                 }
    16.     }
    why doesnt this work??

    plz help me

    Greethings,

    Vince Kieft
     
  2. gmatsura

    gmatsura

    Joined:
    Sep 26, 2012
    Posts:
    15
  3. A_never_kill

    A_never_kill

    Joined:
    Jan 7, 2014
    Posts:
    81