Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Coolguy347 · Oct 24, 2014 at 06:23 AM · error

Help!Error CS0266

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class Item : MonoBehaviour {

 public string itemName;
 public int itemID;
 public string itemDescription;
 public Texture2D itemIcon;
 public int itemPower;
 public int itemSpeed;
 public int itemDamage;
 public bool multiItems;
 public int itemCounter;
 private static int autoIndex = 0;
 public ItemType itemType;

 public enum ItemType{
     Material,
     Placable,
     Hand,
     Head,
     Chest,
     Legs,
     Boots,
     Food,
     Water,
     Weapon,
     Tool,
     Other,




 }

 public Item(){

     }

 public Item(ItemType type) {
      itemType = type;
 
 }

 public Item(Dictionary<string, string> dict) {
     itemName = dict["itemName"];
     itemID ++;
     itemDescription = dict["itemDescription"];
     itemIcon = Resources.Load<Texture2D> ("ItemIcons/"  + dict["itemName"]);
     itemType = System.Enum.Parse(typeof(Item.ItemType), dict ["itemType"].ToString ());
     itemPower = int.Parse (dict["itemPower"]);
     itemSpeed = int.Parse (dict["itemSpeed"]);
     itemDamage = int.Parse (dict["itemDamage"]);    
     multiItems = bool.Parse (dict["multiItems"]);
     itemCounter = multiItems ? 1 : 0;
 }
 public Item (string name, string desc,int power,int speed,int damage,ItemType iType, bool mItems){
     itemName = name;
     itemID = autoIndex++;
     itemDescription = desc;
     itemIcon = Resources.Load<Texture2D>("ItemIcons/" + name);
     itemSpeed = speed;
     itemType = iType;
     multiItems = mItems;
     itemCounter = multiItems ? 1 : 0;
     }

 public Item (string name, int id,string desc,int power,int speed,int damage,ItemType type, bool mItems){
             itemName = name;
             itemID = id;
             itemDescription = desc;
             itemIcon = Resources.Load<Texture2D> ("ItemIcons/" + name);
             itemSpeed = speed;
             itemType = type;
             multiItems = mItems;
             itemCounter = multiItems ? 1 : 0;
     }
 public Item (string name, int id,string desc,int power,int speed,int damage,ItemType type, bool mItems,int counter){
             itemName = name;
             itemID = id;
             itemDescription = desc;
             itemIcon = Resources.Load<Texture2D> ("ItemIcons/" + name);
             itemSpeed = speed;
             itemType = type;
             multiItems = mItems;
             itemCounter = counter;
     }







} is code I get error Cs0266 "Cannot implicitly convert type 'object' to Item.ItemType.An explicit conversation exists.(Are you using a cast?). Line 54,17.HELP!!!

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

1 Reply

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

Answer by Dimling · Oct 24, 2014 at 07:45 AM

The following code is the one that crashes your code:

 itemType = System.Enum.Parse(typeof(Item.ItemType), dict ["itemType"].ToString ());
 

And the reason is as the error says: Cannot implicitly convert type 'object' to Item.ItemType.An explicit conversation exists.

So what you have to do is to append (ItemType) in front of the System.Enum part.

So simply just change the code above with the following code:

 itemType = (ItemType)System.Enum.Parse(typeof(Item.ItemType), dict ["itemType"].ToString ());
 

Now it should work! :)

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 Coolguy347 · Oct 25, 2014 at 01:19 AM 0
Share

Thanks!!!!!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Can you help with my errors? All are similar... 1 Answer

Runtime Error 1 Answer

Hack And Slash Tutorial - Character Generator [Errors] 0 Answers

Blenders Animations playing backwards in unity 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