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 john 9 · May 12, 2011 at 10:59 AM · access

Please someone help with this please been trying to get this working for 4 days

The problem is i have 2 game object 1. is my character 2. is The Mad Doc that has the animations attached to it.

now the problem is i have a script attached to the character called "Die Script" and i want to write some code in there that will initialize an animation from the mad doc animation script. I will show you both of the codes (If any one requires more info please let me know on here or skype:johnesslemont012)

Die Script

private var dead = false; private var dying = false;

var mydeadsound : AudioClip;

function OnControllerColliderHit(hit : ControllerColliderHit) {

//if hit fallout and player is not already dead if((hit.gameObject.tag == "fallout")&&(!dying)) { dying=true; HealthControl.LIVES -=1;

AudioSource.PlayClipAtPoint(mydeadsound,transform.position); yield WaitForSeconds(2.7);

dead = true;

}

}

function LateUpdate() { if(dead)

{

transform.position = Vector3(69.05988,0.8250099,0.01707077);

dead = false; dying = false;

}

}

and here is the mad doc animation script which is called "Walk"

function Awake() { animation["Idle"].layer = 0; animation["Run"].layer = 1; animation["Jump"].layer = 2; animation["Dead"].layer = 3; }

function Update() { if (Input.GetKey("d")) { animation["Run"].wrapMode = WrapMode.Loop; animation.Play("Run");

} else{ if (Input.GetKeyUp("d")) animation.Stop(); animation["Idle"].wrapMode = WrapMode.Loop; }

if (Input.GetKey("a")){ animation["Run"].wrapMode = WrapMode.Loop; animation.Play ("Run"); } else{ if (Input.GetKeyUp("a")) animation.Stop(); animation.CrossFade ("Idle");

}

if (Input.GetKey("right")) { animation["Run"].wrapMode = WrapMode.Loop; animation.Play("Run");

} else{ if (Input.GetKeyUp("right")) animation.Stop(); animation["Idle"].wrapMode = WrapMode.Loop; }

if (Input.GetKey("left")){ animation["Run"].wrapMode = WrapMode.Loop; animation.Play ("Run"); } else{ if (Input.GetKeyUp("left")) animation.Stop(); animation.CrossFade ("Idle");

}

if (Input.GetButtonDown("Jump")) { animation.CrossFade("Jump"); } else{ animation.CrossFade("Idle"); }

}

Comment
Add comment · Show 3
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 GesterX · May 12, 2011 at 01:30 PM 0
Share

Can you edit your post so the code is formatted correctly. Highlight all of your code. Click the code button twice.

avatar image Eric5h5 · May 12, 2011 at 01:53 PM 0
Share

Clicking the code button once is sufficient...clicking twice undoes the formatting.

avatar image john 9 · May 12, 2011 at 01:59 PM 0
Share

There you go Thakns

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ferazel · May 12, 2011 at 03:29 PM

The easiest way would be to make a variable in the die script that links it directly to the MadDoc script. So in your Die Script put a variable:

public MadDocScript scriptObj; 

Then in the editor you should see a variable on your DieScript that you can drag and drop the MadDoc component onto. Then within the DieScript you may access any public members/methods on the MadDoc script via the scriptObj variable. So in your DieScript it could be something like:

void Update() { 
   if(Input.GetKey("d")) {
      scriptObj.InitializeAnimation();
   }
}

or something similar to that.

Comment
Add comment · Show 2 · 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 john 9 · May 12, 2011 at 05:01 PM 0
Share

How ouwld i write that in java as i am a complete noob at c#

avatar image flaviusxvii · May 13, 2011 at 05:45 PM 0
Share

Java =/= Javascript. Please don't confuse them. Use JS as shorthand for Javascript if you must.

Also, learn to convert JS and C#, there really are just a few things you generally have to do. Fix variable declarations and whatnot. Clicking back and forth between JS and C# in the Unity reference will show you differences.

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

No one has followed this question yet.

Related Questions

Last time I'll ask for help on this lol 2 Answers

Access on child's trigger in parent script 1 Answer

GetComponent keeps returning null 3 Answers

problems accessing variables and functions in another script 1 Answer

Cannot access a variable in another Script. 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