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
1
Question by JJNCreator · Jun 16, 2012 at 09:26 PM · movementmeshblenderrenderersword

Sword Mesh renderer script

hey guys. i have a character model that i made in blender and imported to Unity. it has a sword and an attack animation that is part of the armature that i want both in the character's hand and put away while not in combat. I spent all day in Blender, but i couldn't find a way to properly do that. So, i just put the sword (which i imported seperately) as a child object of the armature in Unity.

i want to have two swords on the model, one on his side and one in his hand. When in combat, i want the mesh renderer of the sword in the hand on. if its not in combat, i want the mesh renderer of the sword on the side on. do you think there's a c# script or JavaScript for this? Thanks!

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
1
Best Answer

Answer by whydoidoit · Jun 16, 2012 at 09:29 PM

Yeah no problem :)

JS:

    var swordBySide : MeshRenderer;
    var swordInHand : MeshRenderer;

    function EnterCombatMode() {
         swordBySide.enabled = false;
         swordInHand.enabled = true;
     }

     function ExitCombatMode() {
         swordBySide.enabled = true;
         swordInHand.enabled = false;
    
     }

Attach this to you character and then drag and drop the gameobjects of the two swords on the inspector and call these functions when entering and exiting combat mode by doing:

     SendMessage("EnterCombatMode"); 

from another script on the same game object.

Comment
Add comment · Show 17 · 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 JJNCreator · Jun 17, 2012 at 01:39 AM 0
Share

the mesh or the entire object? its only letting me drag and drop meshes.

avatar image whydoidoit · Jun 17, 2012 at 09:16 PM 0
Share

It will accept you dragging and dropping the thing that has a mesh renderer attached to it. That should be the mesh of the sword and it's associated game object.

avatar image JJNCreator · Jun 18, 2012 at 09:23 PM 0
Share

thanks. another question, how can i have this work with the attack animation through animation.Play? here's the script im working on

using UnityEngine; using System.Collections;

public class AttackAnimation : $$anonymous$$onoBehaviour {

 // Use this for initialization
 void Start () {
     animation.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
 }
 
 // Update is called once per frame
 void Update () {
     if($$anonymous$$athf.Abs(Input.GetAxis("Attack")) > 0) 
             animation.Play("attack");
             Send$$anonymous$$essage("EnterCombat$$anonymous$$ode");
     
         animation.CrossFade("attack");
         Send$$anonymous$$essage("ExitCombat$$anonymous$$ode");
     
         
         
 
 }

}

this is c# because i tried java but it didnt work with the animation, and that got fixed in c#, but the mesh rendering of the swords isnt working correctly. i might be able to figure it out at some point, but do u have any suggestions? anything in c# would be great.

avatar image whydoidoit · Jun 18, 2012 at 09:26 PM 0
Share

What exactly isn't working? BTW you should just use animation.CrossFade("attack") rather than that and Play.

avatar image JJNCreator · Jun 18, 2012 at 09:58 PM 0
Share

well, im not exactly sure since i messed with the mesh renderers, but the mesh of one of the swords is still on, even though i have the codes you gave me about Send$$anonymous$$essage in the script. i also add some mesh components to the game objects of the swords. do u think u can help me on this? BTW i changed the animation.Play to CrossFade.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why isn't this mesh not appearing properly? 0 Answers

Mesh Problems 1 Answer

Changing two different objects renderer colour 1 Answer

Assign textures to Blender Suicidator city mesh 0 Answers

How to make UV maps offset the same way? 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