• 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 Wesker_Kai · Apr 29, 2012 at 08:44 AM · scriptingbasics

How to fix error CS0029: Cannot implicitly convert type `string' to `bool'

HI All guy, I have a question about Unity. I have written a script bit it doesn't work

Assets/Menu.cs(7,17): error CS0029: Cannot implicitly convert type string' to bool'

 using UnityEngine;

using System.Collections;

public class Menu : MonoBehaviour {

 void OnCollisionEnter(Collision collision){
     if(gameObject.tag=("Player"));
     GameObject.Instantiate(Resources.Load("Button"));
 }    

}

Comment
Add comment
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

4 Replies

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

Answer by syclamoth · Apr 29, 2012 at 08:48 AM

This line here:

 if(gameObject.tag=("Player"));

Does nothing. You have two important syntax errors- first, you are putting a semicolon at the end of an if-statement (which will stop it from functioning properly) and second you are using the assignment operator, rather than the evaluation operator (= instead of ==). Try this instead:

 if(gameObject.tag == "Player")
 {
     // stuff
 }
Comment
Add comment · Show 2 · 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
avatar image Wesker_Kai · Apr 29, 2012 at 08:51 AM 1
Share

LI$$anonymous$$E THIS?

using UnityEngine; using System.Collections;

public class $$anonymous$$enu : $$anonymous$$onoBehaviour {

 void OnCollisionEnter(Collision collision){
     if(gameObject.tag=="Player")
     GameObject.Instantiate(Resources.Load("Button"));
 }    

}

avatar image syclamoth · Apr 29, 2012 at 08:52 AM 0
Share

YES.

avatar image
3

Answer by Lo0NuhtiK · Apr 29, 2012 at 08:46 AM

if(gameObject.tag == "Player") or if(gameObject.CompareTag("Player"))

Comment
Add comment · Show 2 · 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
avatar image syclamoth · Apr 29, 2012 at 08:49 AM 2
Share

Damn ninjas.

avatar image Lo0NuhtiK · Apr 29, 2012 at 08:50 AM 1
Share

lol ... yeah, but you solved the next error before it happened ... I wasn't paying any attention to anything else other than the direct question and didn't even notice the semicolon :D

avatar image
0

Answer by ArturasLTU-RUS · Oct 16, 2013 at 03:09 AM

hey guys I have a problem as well that u might help with: this is the code: { Debug.Log("Starting animation split process..."); string assetPath = AssetDatabase.GetAssetPath(DestinationAsset);

     if (assetPath.Contains(objectName))
     {
         ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter;
         modelImporter.clipAnimations = true;
         modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;

         // Set the number of animations here
         int numAnimations = total;
         ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[numAnimations];

         XmlNodeList list = doc.GetElementsByTagName("Data");
         int i = 0;
         foreach (XmlNode node in list)
         {
             XmlAttributeCollection child = node.Attributes;
             string name = "";
             int sf = 0;
             int ef = 0;

             foreach (XmlNode nd in child)
             {
                 if (nd.Name == "name")
                     name = nd.Value;
                 if (nd.Name == "startFrame")
                     sf = int.Parse(nd.Value.Replace("f", ""));
                 if (nd.Name == "endFrame")
                     ef = int.Parse(nd.Value.Replace("f", ""));
             }

             bool loop = false;
             string nm = name.ToLower();

             if (nm.Contains("idle") || nm.Contains("walk") || nm.Contains("sprint") || nm.Contains("run") || nm.Contains("strafe"))
                 loop = true;

             animations[i] = SetClipAnimationNew(nm, sf, ef, loop);
             i++;
         }

         modelImporter.clipAnimations = animations;

         Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject));
         EditorUtility.SetDirty(asset);
         AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);  
     }
 }

this what is says in unity : Assets/GameContent/Motiontracks/Editor/AnimationImporter.cs(26,27): error CS0029: Cannot implicitly convert type bool' to UnityEditor.ModelImporterClipAnimation[]'

if anyone could help :)

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
avatar image lexen1 · Jan 18, 2014 at 12:15 AM 0
Share

Which line is 26?

avatar image
0

Answer by Skorpio2134 · Nov 12, 2013 at 01:30 AM

i need help with the same problem and i have no syntax errors heres my code plz help

 enter code hereusing UnityEngine;
 using System.Collections;
 
 public class Goal1 : MonoBehaviour {
     public string text;
     public bool display = false;
     
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void OnTriggerEnter(Collider iCollide){
         if(iCollide.transform.name == "Player") {
         display = true;
     }
 }
 
     void OnGUI() {
             if(display == true) {
             
             GUI.Box (new Rect(0,50,Screen.width,Screen.height-50), text);
     }
 }
 
 }
 
 
Comment
Add comment · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Very simple script - why isn't it working? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Creating & accessing a function from a diffrent "OnTriggerEnter" Function 1 Answer

Setting Scroll View Width GUILayout 1 Answer


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