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 Foolish_Smart_ · Mar 22, 2014 at 04:58 PM · javascriptpick up objectjavascripting

Animating main player when click on object

Hii,,

I am new to unity as well as scripting plz bare me..

i am trying to play an animation of my main player when i click on the other object...

for instance i am trying to do script(Java only) to pick up an object from ground..

i have a small cube on my plane now i want to play my pick up animation (Which is on my player)& collect that cube when i click on that cube...

plz plz plz help me out..

There is another problem when i used that animation on my player using following clip

if ( Input.GetMouseButton(2) ) { animation.Play("Pick up"); } } then it play animation only when i keep press the said button

Actuly i want to play full animation when i click once.

(Sorry for my bad English as it was not my language)

Comment
Add comment · Show 6
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 $$anonymous$$ · Mar 22, 2014 at 05:02 PM 0
Share

if you put inspector to Debug mode click the animation. is there a number 2 or 1 in the animation type box?

avatar image $$anonymous$$ · Mar 22, 2014 at 05:04 PM 0
Share

sorry, reread you're script where it says if(Input.Get$$anonymous$$ouseButton)

it should be if(Input.GetButtonDown("Fire2"))

avatar image Foolish_Smart_ · Mar 23, 2014 at 02:11 AM 0
Share

Thank you for reply

As i see animation show 1 number in debug mode

and other scrip gives me a same effect....

avatar image Foolish_Smart_ · Mar 23, 2014 at 09:29 AM 0
Share

Plz help me

avatar image $$anonymous$$ · Mar 23, 2014 at 12:51 PM 0
Share

hmmm, do u have Skype maybe if i could see what you mean and look at your scripts it would help me help you.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Mar 23, 2014 at 03:35 PM

this is what i would use:

Item that you want to be picked up as a script put a collider on it and set it as a trigger.

script on the item should say:

var Player : Transform;

OnTriggerEnter()

{

Player.SendMessage("PickUp");

}

script on player

function PickUp()

{

if(Input.GetButtonDown"Fire2")

 {
  animation.CrossFade("animationname");
 }

}

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
avatar image
0

Answer by ivan2532 · Mar 23, 2014 at 02:10 PM

Hello Foolish_Smart_,

There are bunch of ways to do this, I will show you one way:

Create a JavaScript and write down this code:

 var playerObject : GameObject; // attach player game object in inspector
 var pickUpAnim : AnimationClip; // attach animation file in inspector
 
 function OnMouseDown()
 {
    //here insert your code for pick up
    playerObject.animation.CrossFade(pickUpAnim.name);
 }

Attach it to the item.

Good luck, Ivan

Comment
Add comment · Show 4 · 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 $$anonymous$$ · Mar 23, 2014 at 03:18 PM 0
Share

That won't work as whenever you press the mouse button the animation will play and that is why i suggested the on trigger method as you will have to be next to the object

avatar image Foolish_Smart_ · Mar 23, 2014 at 06:57 PM 0
Share

Thanks both of you i tried both of your scripts as far as considering yolo22 script it is better view but wont work as trigger function is work properly but it not animate a player.. I think the function is not calling a pick up function from player as player enter in the trigger..What should i do..

As far as considering $$anonymous$$script it works but when ever i click on the object it got animated irrespective of position of the object ..what should i do to fixed it ..

I would like to learn both the ways as i am in learning phase ..

once again thanks for your valuable inputs..

avatar image $$anonymous$$ · Mar 23, 2014 at 07:23 PM 0
Share

The Pick-up Function is like when you send a message it does nothing unless you define it.

one thing could be the collider is too small as it goes from the centre of the player not any part of it so maybe try increasing the size?

if you have g mail, we could use Google plus maybe so i could see what is happening. or screen record with Debug.Logs scattered through out the script so i can see where the problem is.

if so here is my Email: $$anonymous$$

avatar image Foolish_Smart_ · Mar 23, 2014 at 08:09 PM 0
Share

I email you totally appreciate your help thanks a lot..:)

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

21 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

Related Questions

creating an object using javascript 1 Answer

';' expected. Insert a semicolon at the end. I already have a ; 1 Answer

javascript to unity javascript conversion 1 Answer

How I can find the complete event of my animation 1 Answer

Gun shooting help 2 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