Use Unity code to generate a GameObject through Xml configuration-a pitfall from the previous two days, unitygameobject

Source: Internet
Author: User

Use Unity code to generate a GameObject through Xml configuration-a pitfall from the previous two days, unitygameobject

1. Resources. Load (path), path is not an absolute path, but a relative path relative to "Resources! For example:

To Instantiate, the code should be as follows:
string man1Path = "Research/FBX/man1/";GameObject weapon = Instantiate(Resources.Load(man1Path + "char_weapon_ani", typeof(GameObject))) as GameObject;

 

(I tried it many times before it was successful ......) 2. I caught a sigh of relief when I read Xml on the Internet last night. I practiced method 1 and somehow fell into the trap. So I went back and sorted out my ideas. I remember that I did not write this in the past, either case1: find another parsing method, either case2: After Class serialization, copy the xml file and deserialize it. I tried two libraries, one of which is System. xml. the Descendants () method is useful in (method 1). The result is IEnumerable and cannot be operated. I think this method is feasible, but I cannot read the value = because the code is also deleted, I skipped this section. ==||| so I switched to Sytem later. xml (case 1). XmlNodeList XmlNode SelectSingleNode () is easier to understand ~ Paste some code:
XmlElement root = doc. DocumentElement; // obtain all <character> ...... </Character> XmlNodeList charactersNodes = root. GetElementsByTagName ("character"); // traverse it and continue to operate foreach (XmlNode characterNode in charactersNodes ){......}

 

3. Add the problem background of GameObject position through code: GameObject human includes the GameObject body, and the body contains human and weapon. We expect human. transform. position = (, 1), body. transform. position = (, 0 ). After the body. transform. parent = human. tranform is set, the body. transform. position is automatically changed to (-1, 0,-1 ). Suppose I set body. transform. position = (, 0), weapon. transform. position to (-,-1 )...... = ....... So suppose I have generated five human users with different positions. We can see that all the images overlap. = waiting for resolution. After the solution is complete, let's make a change ...... Updated: solution: You should not set the position, but set the localPosition to go with the position of the parent ~ 4. For the mesh, Material does not seem to have been attached after obtaining it. Continue to study ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.