Jump to content
  • Advertisement

Howgyn

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

104 Neutral

About Howgyn

  • Rank
    Newbie

Personal Information

  • Interests
    |programmer|
  1. Is that any free software or other great method that used to slice sprite other than TexturePacker Pro? For Unity purpose.   The polygon slice function of TexturePacker Pro is very nice, it suit the size of the sprite. However my TexturePacker Pro trial had finished, and by using Unity Sprite Editor will make my sliced sprite tremble, I don't know why.   Any suggestion for that?
  2. Ok now I understand what you said. Can you suggest anyway how I can edit my code so it work? 
  3. Very sorry though ... It is my mistake.    I mistakenly wrote it as anim, actually what I want to wrote is (theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk")) "theanim" make "GetCurrentAnimatorStateInfo" become red line.  
  4. @Kylotan Here I attached my code below:  (GetCurrentAnimatorStateInfo) get red line and can't compile in Unity void Update() { GameObject characters = GameObject.Find(charactersname); GameObject theanim = GameObject.Find(charactername); if (!Input.GetKey("up") && !Input.GetKey("down") && !Input.GetKey("left") && !(Input.GetKey("right")) && (theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"))) { theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false); theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false); theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false); theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false); theanim.GetComponent<Animator>().SetBool(charactersidlewalk, false); theanim.GetComponent<Animator>().SetBool(charactersbackidle, true); theanim.GetComponent<Animator>().SetBool(charactersrightidle, false); theanim.GetComponent<Animator>().SetBool(charactersleftidle, false); } }
  5. I want to get the current state from Unity Animator. However when I type theanim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"), the code "GetCurrentAnimatorStateInfo" is in red line which Visual Studios indicate that "'Game object' does not contain a definition GetCurrentAnimatorStateInfo and no extension method accepting a first argument of type 'Game object' could be found (are you missing using a directive or an assembly reference)" When I type anim.GetCurrentAnimatorStateInfo(0).IsName("charactersbackwalk"), the code run but the result is not what I want. Therefore, I wonder it is necessary to declare something before using 'GetCurrentAnimatorStateInfo'?
  6. Bottom is the attachment of my mecanim state in Animator. The problem I'm facing now is fail to change multiple sprite mecanim state using C# script. When I move my sprite, I can successfully change it from idle to backwalk state, however it limit my changes solely to backwalk state but not all other states. I want to make it like when I press right arrow key it change to rightwalk state, while press left arrow key to change it to leftwalk state and so on. Unfortunately the if else statement that I declare is not working making my changing movement only stick to one state. I wonder what mistake I made, and how I can fix my code?   I'm a newbie to Unity and not familiar with C#. I just learn it from the official Unity tutorials series. I been searching for many related question regard of the problem but still I can't figure out the solution. This is the first question I ask at Game Stack Exchange, sorry if I violate any rules and please guide me through it. Appreciate anyone help sincerely. Here I attach my code: using UnityEngine; using System.Collections;   public class CharacterMove : MonoBehaviour {     public float MoveSpeed = 1;     float aspectspeedx = Screen.width / 1366;     float aspectspeedy = Screen.height / 768;       // Use this for initialization     void Start()     {         GameObject anim = GameObject.Find("Taoist");         anim.GetComponent<Animator>();     }       // Update is called once per frame     void Update()     {         float MoveSpeed = 1f;         // change the string to your parameter                string characterfrontwalk = "taoist_front_walk";         string characterbackwalk = "taoist_back_walk";         string characterleftwalk = "taoist_left_walk";         string characterrightwalk = "taoist_right_walk";         /* if you want corner walk          string characterrightfrontwalk = "taoist_right_front_walk";         string characterrightbackwalk = "taoist_right_back_walk";         string characterleftfrontwalk = "taoist_left_front_walk";         string characterleftbackwalk = "taoist_left_back_walk";         // to use this corner setting , you must initialize yourself                   */         GameObject character = GameObject.Find("Taoist");         GameObject theanim = GameObject.Find("Taoist");         theanim.GetComponent<Animator>();         theanim.GetComponent<Animator>().SetBool(characterfrontwalk, true);         theanim.GetComponent<Animator>().SetBool(characterbackwalk, false);         theanim.GetComponent<Animator>().SetBool(characterleftwalk, false);         theanim.GetComponent<Animator>().SetBool(characterrightwalk, false);         character.transform.localPosition = new Vector3(character.transform.localPosition.x, character.transform.localPosition.y + 0.05f * MoveSpeed, character.transform.localPosition.z);         character.transform.localPosition = new Vector3(character.transform.localPosition.x - 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);           if (!(Input.GetKey("up") && Input.GetKey("right")) && !(Input.GetKey("up") && Input.GetKey("left")) && !(Input.GetKey("down") && Input.GetKey("right")) && !(Input.GetKey("down") && Input.GetKey("left")))         {             if (Input.GetKey("up"))             {                 theanim.GetComponent<Animator>().SetBool(characterfrontwalk, true);                 theanim.GetComponent<Animator>().SetBool(characterbackwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterleftwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterrightwalk, false);                   character.transform.localPosition = new Vector3(character.transform.localPosition.x, character.transform.localPosition.y + 0.05f * MoveSpeed, character.transform.localPosition.z);             }               if (Input.GetKey("down"))             {                 theanim.GetComponent<Animator>().SetBool(characterfrontwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterbackwalk, true);                 theanim.GetComponent<Animator>().SetBool(characterleftwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterrightwalk, false);                   character.transform.localPosition = new Vector3(character.transform.localPosition.x, character.transform.localPosition.y - 0.05f * MoveSpeed, character.transform.localPosition.z);             }               if (Input.GetKey("left"))             {                 theanim.GetComponent<Animator>().SetBool(characterfrontwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterbackwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterleftwalk, true);                 theanim.GetComponent<Animator>().SetBool(characterrightwalk, false);                   character.transform.localPosition = new Vector3(character.transform.localPosition.x - 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);             }               if (Input.GetKey("right"))             {                 theanim.GetComponent<Animator>().SetBool(characterfrontwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterbackwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterleftwalk, false);                 theanim.GetComponent<Animator>().SetBool(characterrightwalk, true);                   character.transform.localPosition = new Vector3(character.transform.localPosition.x + 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);             }           }       }   /*                   // THIS CODE IS FOR CORNER MOVE , UN-MODIFIED , because im too tired to modify it sorry , you need to think yourself ;)                   if( Input.GetKey("down") && Input.GetKey("left")){   theanim.GetComponent<Animator> ().SetBool ("MoveUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeft", false); theanim.GetComponent<Animator> ().SetBool ("MoveRight", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftDown", true); theanim.GetComponent<Animator> ().SetBool ("MoveRightDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveRightUp", false); theanim.GetComponent<Animator> ().SetBool ("NotMoving", false); character.transform.localPosition = new Vector3 (character.transform.localPosition.x, character.transform.localPosition.y - 0.05f * MoveSpeed, character.transform.localPosition.z); character.transform.localPosition = new Vector3 (character.transform.localPosition.x - 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);   }     if( Input.GetKey("up") && Input.GetKey("right")){   theanim.GetComponent<Animator> ().SetBool ("MoveUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeft", false); theanim.GetComponent<Animator> ().SetBool ("MoveRight", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveRightDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveRightUp", true); theanim.GetComponent<Animator> ().SetBool ("NotMoving", false); character.transform.localPosition = new Vector3 (character.transform.localPosition.x, character.transform.localPosition.y + 0.05f * MoveSpeed, character.transform.localPosition.z); character.transform.localPosition = new Vector3 (character.transform.localPosition.x + 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);   } if( Input.GetKey("down") && Input.GetKey("right")){   theanim.GetComponent<Animator> ().SetBool ("MoveUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeft", false); theanim.GetComponent<Animator> ().SetBool ("MoveRight", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftUp", false); theanim.GetComponent<Animator> ().SetBool ("MoveLeftDown", false); theanim.GetComponent<Animator> ().SetBool ("MoveRightDown", true); theanim.GetComponent<Animator> ().SetBool ("MoveRightUp", false); theanim.GetComponent<Animator> ().SetBool ("NotMoving", false); character.transform.localPosition = new Vector3 (character.transform.localPosition.x, character.transform.localPosition.y - 0.05f * MoveSpeed, character.transform.localPosition.z); character.transform.localPosition = new Vector3 (character.transform.localPosition.x + 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);   }          // Un-MODIFIED corner setting , initialize yourself              */       }   public class LastDirection {     public string thelastdirection; }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!