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

Is there anyway to GetComponent a script that has brackets in its name?

Discussion in 'Scripting' started by Mystique, Dec 12, 2014.

  1. Mystique

    Mystique

    Joined:
    Nov 19, 2014
    Posts:
    40
    for e.g
    Code (JavaScript):
    1. var guardsc : (targetBased)V2 = Guard.gameObject.Getcomponent((targetBased)V2);
    This don't work.
    Because the Coding engine always assumes the brackets are code instructions and not part of my components name.


    It's important that my script name has brackets in it to help differentiate between them easier,
    is there anyway to access scripts with brackets via script?
     
    Last edited: Dec 12, 2014
  2. Megolas

    Megolas

    Joined:
    Apr 6, 2013
    Posts:
    25
    You can use GetComponent("name"), that should solve it.