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

why its not working

Discussion in 'Scripting' started by Prosmatera, Feb 16, 2016.

  1. Prosmatera

    Prosmatera

    Joined:
    Dec 21, 2015
    Posts:
    89
    Hi, i have this script which is supposed to enable the script attached to the object on collison but something is wrong and its not working
    using UnityEngine;
    using System.Collections;

    public class EnableComponents1 : MonoBehaviour
    {
    private MovingPlatform myLight;


    void Start()
    {
    myLight = GetComponent<MovingPlatform>();
    }


    void OnCollisionEnter(Collision col)
    {
    if (col.gameObject.name == "Plane")
    {
    myLight.enabled = true;
    }
    }
    }

    it works well when i use OnMouseButtonDown
     
  2. wheatgrinder

    wheatgrinder

    Joined:
    Mar 20, 2015
    Posts:
    21
    maybe you dont have colliders on the other thing?
    the colliders are set as triggers?
    try name.contains("Plane") instead of name="Plane"
     
    Last edited: Feb 16, 2016
    Prosmatera likes this.
  3. joewode

    joewode

    Joined:
    Dec 3, 2014
    Posts:
    35
    Is 'plane' the name of the platform this script is supposed to be controlling? I'm making assumptions here because I don't have enough info but it looks like you might be telling your platform's collider to look for collisions with itself. Since it cant do this the condition will always be false and your script won't activate.

    I'm assuming there is a 'player' object. Switch out 'plane' with the name of your player object so it can look for collisions with that instead.
     
    Prosmatera likes this.