Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Lom-Ali · Jan 03, 2019 at 11:42 PM · 2d gamespritesbones2d rotation

Can´t attach 2D Bones to the Character Script

I have made a 2DCharakter with 2DBones (Anima2D) and i can´t attach them to the Gameobject in the Character Script because it only requires Sprite renderers. The Character Script allows the 2D player to rotate his Arms like in those 2D sidescroll shooter games and all I want to do is to attach those Bones (which are attached to the ArmSprites) to the first Hand, but I can only attach normal Sprites. This is the Character Script:

 public class Character : MonoBehaviour, IDamageable {
 
     [SerializeField] Animator HandsAnimator;                //Hands animator for management hands and guns animation
     [SerializeField] SpriteRenderer HeadTransform;            //To control the position and rotation of the head
     [SerializeField] Transform HandsTransform;                //To control the position and rotation of the hands
     [SerializeField] Transform ShotStartTransform;            //To determine the start of the shot
     [SerializeField] float HandsOnDeathRotation;            //Hack, for the position of the hands at death, you can do in the animator.
     [SerializeField] float HeadOnDeathRotation;                //Hack
     [SerializeField] float DeathTime;                        //Hack
     [SerializeField] float DestroyCharacterAfterDeathTime;
     [SerializeField] Transform CameraTargetPoint;            //The point behind which the camera will follow
     [SerializeField] Renderer MainRenderer;                    //For autoaim and AILogic
 
     //Parts of the hand, for modification possibilities
     [Header("FirstHand")]
     [SerializeField] SpriteRenderer FirstShoulder;
     [SerializeField] SpriteRenderer FirstForearm;
     [SerializeField] SpriteRenderer FirstForearmOutline;
 
     //Parts of the hand, for modification possibilities
     [Header("SecondHand")]
     [SerializeField] SpriteRenderer SecondShoulder;
     [SerializeField] SpriteRenderer SecondForearm;
     [SerializeField] SpriteRenderer SecondForearmOutline;
 
     //Sounds
     [Space(10),Header("Sounds")]
     [SerializeField] AudioClipPreset JumpSound;
     [SerializeField] AudioClipPreset StepSound;
 
     private int GroundCollided;                                        //Touch counter to ground
     private int CurrentWeaponIndex;                                    //Index weapon in hands
     private List<WeaponEntity> Weapons = new List<WeaponEntity>();    //Weapons list
     private Loot LootInInteractionZone;                                //Not null if character is near loot
 
     private WeaponEntity selectedWeapon;                            //Weapon in hands
 
     private HashSet<Collider2D> TriggeredObjects = new HashSet<Collider2D>();        //To control the re-trigger
     private Collider2D LastColision;                                //For stop move animation on dynamic props
 
     #region Public properties
 
     public CharacterDescription Description { get; private set; }
     public bool IsUserControlled { get { return  Input == InputController.Instance.CurrentController; } }
     public bool IsBot { get { return  Input is AIController; } }
     public GamePanel GamePanel { get { return GamePanel.Instance; } }
     public Rigidbody2D RB { get; private set; }
     public Animator Animator { get; private set; }
     public Vector2 Position { get { return transform.position; } }
     public Transform GetTransform { get { return transform; } }
     public Renderer GetRenderer { get { return MainRenderer; } }
     public int DirectionByX { get; private set; }
     public Animator GetHandsAnimator { get { return HandsAnimator; } }
     public WeaponEntity SelectedWeapon {
         get {
             return selectedWeapon;
         }
         private set {
             if (selectedWeapon != null) {
                 selectedWeapon.DeselectWeapon();
             }
             selectedWeapon = value;
             selectedWeapon.SelectWeapon(this);
         }
     }
     public LayerMask EnemyMask {
         get {
             if (B.Layers.AlliesMask.LayerInMask(gameObject.layer)) {
                 return B.Layers.EnemyMask;
             } else {
                 return B.Layers.AlliesMask;
             }
         }
     }
     public bool InAir { get { return GroundCollided == 0; } }
     public Transform GetShotStartTransform { get { return ShotStartTransform; } }
     public float Health { get; private set; }
     public bool IsDead { get; private set; }
 
     InputBaseClass Input { get; set; }
 
     #endregion //Public properties
 
     #region Private properties
 
     private LayerMask GroundMask { get { return B.Layers.GroundMask; } }
     private LayerMask LootMask { get { return B.Layers.LootMask; } }
     private Vector2 DirectionToAim { get { return Input.AimPos - (Vector2)transform.position; } }
 
     #endregion //Private properties
 
     #region Instantiation
 
     /// <summary> Create and initialisation character </summary>
     /// <param name="spawnPoint"> Spawn character position </param>
     /// <param name="description"> Character description</param>
     public static Character CreateCharacter (Vector3 spawnPoint, CharacterDescription description) {
         var newCharacter = Instantiate(description.CharacterPrefab);
         newCharacter.transform.position = spawnPoint;
         newCharacter.InitCharacter(description);
         return newCharacter;
     }
 
     /// <summary> Initialisation character after start </summary>
     /// <param name="description"> Character description</param>
     private void InitCharacter (CharacterDescription description) {
         Description = description;
         Health = Description.MaxHealth;
         RB = GetComponent<Rigidbody2D>();
         Animator = GetComponent<Animator>();
 
         SelectedWeapon = new WeaponEntity(this, Description.StartedWeapon);
         SelectedWeapon.CartridgesTotal = SelectedWeapon.Weapon.MaxCartridges;
         Weapons.Add(SelectedWeapon);
 
         if (RB == null) { Debug.LogError("RigidBody2D not found", this); }
         if (Animator == null) { Debug.LogError("Animator not found", this); }
 
         Animator.runtimeAnimatorController = Description.Animator;
 
         //Set hands
         FirstShoulder.sprite = Description.FirstShoulder;
         FirstForearm.sprite = Description.FirstForearm;
         FirstForearmOutline.sprite = Description.FirstForearmOutline;
         SecondShoulder.sprite = Description.SecondShoulder;
         SecondForearm.sprite = Description.SecondForearm;
         SecondForearmOutline.sprite = Description.SecondForearmOutline;
 
         //Set head
         HeadTransform.sprite = Description.HeadSprite;
     }

What do i have to Change in the Character Script in Line 24 and line 129?

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

Answer by cdr9042 · Jan 04, 2019 at 02:54 AM

You have to use SpriteMeshRenderer (Created by 2D Object > Sprite Mesh). To have a sprite mesh, right click on your sprite texture, then Create > Anima2D > Sprite Mesh. Then attach the bone to your sprite mesh by first having that SpriteMeshRenderer in the scene, then open the SpriteMesh Editor and bind the bone.

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.

Follow this Question

Answers Answers and Comments

112 People are following this question.

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

Related Questions

Sprite managed by Sprite Renderer doesn't shows up in play mode 0 Answers

2D game camera background between sprites 0 Answers

Unity 2D: query for "mask/layer" bit on screen space without collider 1 Answer

How can my sprite move to new direction it's facing not keep going to old direction? 0 Answers

How do I get the sprite pointing the right direction? 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