Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by 14ercooper · Aug 10, 2015 at 10:23 PM · compiler errorstandard-assetscross-platform

Unity Standard Assets' CrossPlatformInputInitialize has errors

I have imported the CrossPlatformInputInitialize.cs from Unity Standard Assets so that I can use the unity first person controller. In the editor, I have no issues what-so-ever. The game runs without an errors, and console show no errors. However, once I attempt to build the game, I get the following in the console:

  • Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(3,7): error CS0246: The type or namespace name UnityEditor' could not be found. Are you missing a using directive or an assembly reference? - Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(98,24): error CS0246: The type or namespace name BuildTargetGroup' could not be found. Are you missing a using directive or an assembly reference?

  • Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(7,6): error CS0246: The type or namespace name InitializeOnLoad' could not be found. Are you missing a using directive or an assembly reference? - Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(7,6): error CS0246: The type or namespace name InitializeOnLoadAttribute' could not be found. Are you missing a using directive or an assembly reference?

  • Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(141,52): error CS0246: The type or namespace name BuildTargetGroup' could not be found. Are you missing a using directive or an assembly reference? - Assets/Scripts/CrossPlatformInput/CrossPlatformInputInitialize.cs(3,7): error CS0246: The type or namespace name UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

  • Error building Player because scripts had compiler errors

My script hasn't been modified and looks like this:

 using System;
 using System.Collections.Generic;
 using UnityEditor;
 
 namespace UnityStandardAssets.CrossPlatformInput.Inspector
 {
     [InitializeOnLoad]
     public class CrossPlatformInitialize
     {
         // Custom compiler defines:
         //
         // CROSS_PLATFORM_INPUT : denotes that cross platform input package exists, so that other packages can use their CrossPlatformInput functions.
         // EDITOR_MOBILE_INPUT : denotes that mobile input should be used in editor, if a mobile build target is selected. (i.e. using Unity Remote app).
         // MOBILE_INPUT : denotes that mobile input should be used right now!
 
         static CrossPlatformInitialize()
         {
             var defines = GetDefinesList(buildTargetGroups[0]);
             if (!defines.Contains("CROSS_PLATFORM_INPUT"))
             {
                 SetEnabled("CROSS_PLATFORM_INPUT", true, false);
                 SetEnabled("MOBILE_INPUT", true, true);
             }
         }
 
 
         [MenuItem("Mobile Input/Enable")]
         private static void Enable()
         {
             SetEnabled("MOBILE_INPUT", true, true);
             switch (EditorUserBuildSettings.activeBuildTarget)
             {
                 case BuildTarget.Android:
                 case BuildTarget.iOS:
                 case BuildTarget.WP8Player:
                 case BuildTarget.BlackBerry:
                 case BuildTarget.PSM: 
                 case BuildTarget.Tizen: 
                 case BuildTarget.WSAPlayer: 
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have enabled Mobile Input. You'll need to use the Unity Remote app on a connected device to control your game in the Editor.",
                                                 "OK");
                     break;
 
                 default:
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have enabled Mobile Input, but you have a non-mobile build target selected in your build settings. The mobile control rigs won't be active or visible on-screen until you switch the build target to a mobile platform.",
                                                 "OK");
                     break;
             }
         }
 
 
         [MenuItem("Mobile Input/Enable", true)]
         private static bool EnableValidate()
         {
             var defines = GetDefinesList(mobileBuildTargetGroups[0]);
             return !defines.Contains("MOBILE_INPUT");
         }
 
 
         [MenuItem("Mobile Input/Disable")]
         private static void Disable()
         {
             SetEnabled("MOBILE_INPUT", false, true);
             switch (EditorUserBuildSettings.activeBuildTarget)
             {
                 case BuildTarget.Android:
                 case BuildTarget.iOS:
                 case BuildTarget.WP8Player:
                 case BuildTarget.BlackBerry:
                     EditorUtility.DisplayDialog("Mobile Input",
                                                 "You have disabled Mobile Input. Mobile control rigs won't be visible, and the Cross Platform Input functions will always return standalone controls.",
                                                 "OK");
                     break;
             }
         }
 
 
         [MenuItem("Mobile Input/Disable", true)]
         private static bool DisableValidate()
         {
             var defines = GetDefinesList(mobileBuildTargetGroups[0]);
             return defines.Contains("MOBILE_INPUT");
         }
 
 
         private static BuildTargetGroup[] buildTargetGroups = new BuildTargetGroup[]
             {
                 BuildTargetGroup.Standalone,
                 BuildTargetGroup.WebPlayer,
                 BuildTargetGroup.Android,
                 BuildTargetGroup.iOS,
                 BuildTargetGroup.WP8,
                 BuildTargetGroup.BlackBerry
             };
 
         private static BuildTargetGroup[] mobileBuildTargetGroups = new BuildTargetGroup[]
             {
                 BuildTargetGroup.Android,
                 BuildTargetGroup.iOS,
                 BuildTargetGroup.WP8,
                 BuildTargetGroup.BlackBerry,
                 BuildTargetGroup.PSM, 
                 BuildTargetGroup.Tizen, 
                 BuildTargetGroup.WSA 
             };
 
 
         private static void SetEnabled(string defineName, bool enable, bool mobile)
         {
             //Debug.Log("setting "+defineName+" to "+enable);
             foreach (var group in mobile ? mobileBuildTargetGroups : buildTargetGroups)
             {
                 var defines = GetDefinesList(group);
                 if (enable)
                 {
                     if (defines.Contains(defineName))
                     {
                         return;
                     }
                     defines.Add(defineName);
                 }
                 else
                 {
                     if (!defines.Contains(defineName))
                     {
                         return;
                     }
                     while (defines.Contains(defineName))
                     {
                         defines.Remove(defineName);
                     }
                 }
                 string definesString = string.Join(";", defines.ToArray());
                 PlayerSettings.SetScriptingDefineSymbolsForGroup(group, definesString);
             }
         }
 
 
         private static List<string> GetDefinesList(BuildTargetGroup group)
         {
             return new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';'));
         }
     }
 }
 

I don't know what is wrong, can anyone help?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 14ercooper · Aug 11, 2015 at 02:07 AM 0
Share

I can tell it's because the compiler can't find UnityEditor, BuildTergetGroup, and InitializeOnLoadAttribute; but I don't know what to do to fix it

avatar image 14ercooper · Aug 11, 2015 at 12:46 PM 0
Share

Is there a way for me to simply disable this script, without breaking the player controllers?

avatar image HamFar · Mar 08, 2017 at 11:57 AM 0
Share

Could someone please help me understand line 113? Is this a foreach-ternary combo? Does it mean foreach variable 'group' in 'mobile' if 'group' actually was in 'mobile' then 'mobileBuildTargetGroups' otherwise 'buildTargetGroups'? How do I read this line correctly?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by 14ercooper · Aug 11, 2015 at 03:36 PM

I managed to fix the error. It now only works as a standalone build, but it can be compiled. using System; using System.Collections.Generic; using UnityEngine;

 namespace UnityStandardAssets.CrossPlatformInput.Inspector
 {
     //[InitializeOnLoad]
     public class CrossPlatformInitialize
     {
         // Custom compiler defines:
         //
         // CROSS_PLATFORM_INPUT : denotes that cross platform input package exists, so that other packages can use their CrossPlatformInput functions.
         // EDITOR_MOBILE_INPUT : denotes that mobile input should be used in editor, if a mobile build target is selected. (i.e. using Unity Remote app).
         // MOBILE_INPUT : denotes that mobile input should be used right now!
 
         static CrossPlatformInitialize()
         {
             return;
         }
 
 
         private static void Enable()
         {
             return;
         }
 
 
         private static bool EnableValidate()
         {
             return true;
         }
 
 
         private static void Disable()
         {
             return;
         }
 
 
         private static bool DisableValidate()
         {
             return true;
         }
 
 
         //private static BuildTargetGroup[] buildTargetGroups = new BuildTargetGroup[]
         //    {
         //        BuildTargetGroup.Standalone,
         //        BuildTargetGroup.WebPlayer,
         //        BuildTargetGroup.Android,
         //        BuildTargetGroup.iOS,
         //        BuildTargetGroup.WP8,
         //        BuildTargetGroup.BlackBerry
         //    };
 
         //private static BuildTargetGroup[] mobileBuildTargetGroups = new BuildTargetGroup[]
         //    {
         //        BuildTargetGroup.Android,
         //        BuildTargetGroup.iOS,
         //        BuildTargetGroup.WP8,
         //        BuildTargetGroup.BlackBerry,
         //        BuildTargetGroup.PSM, 
         //        BuildTargetGroup.Tizen, 
         //        BuildTargetGroup.WSA 
         //    };
 
 
         private static void SetEnabled(string defineName, bool enable, bool mobile)
         {
             return;
         }
 
 
         //private static List<string> GetDefinesList(BuildTargetGroup group)
         //{
         //    return new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';'));
         //}
     }
 }
 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

importing standard assets fails 2 Answers

Standard assets broken? 0 Answers

Modifying Waypoint Circuit script 3 Answers

Where did Sunshafts go? 1 Answer

Water/Beach foam with unity water 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges