x


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"));
 }    

}

more ▼

asked Apr 29, 2012 at 08:44 AM

Wesker_Kai gravatar image

Wesker_Kai
3 11 10 11

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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
 }
more ▼

answered Apr 29, 2012 at 08:48 AM

syclamoth gravatar image

syclamoth
18.4k 20 28 118

YES.

Apr 29, 2012 at 08:52 AM syclamoth

LIKE THIS?

using UnityEngine; using System.Collections;

public class Menu : MonoBehaviour {

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

}

Apr 29, 2012 at 08:51 AM Wesker_Kai
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Apr 29, 2012 at 08:46 AM

Lo0NuhtiK gravatar image

Lo0NuhtiK
6.4k 5 17 58

Damn ninjas.

Apr 29, 2012 at 08:49 AM syclamoth

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

Apr 29, 2012 at 08:50 AM Lo0NuhtiK
(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Oct 16, 2013 at 03:09 AM

ArturasLTU-RUS gravatar image

ArturasLTU-RUS
1 3 2 2

Which line is 26?

Jan 18 at 12:15 AM lexen1
(comments are locked)
10|3000 characters needed characters left

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);
     }
 }
 
 }
 
 
more ▼

answered Nov 12, 2013 at 01:30 AM

Skorpio2134 gravatar image

Skorpio2134
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9280
x230

asked: Apr 29, 2012 at 08:44 AM

Seen: 7226 times

Last Updated: Jan 18 at 12:15 AM