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 /
  • Help Room /
avatar image
0
Question by fernandovt · Aug 30, 2015 at 04:55 AM · animationscript.musicc #

Help a tired man with #C..... (Record Player in Horror Game)

So i have easy questions, but i am bad coding and have been working for hours without solving anything:(, this is a #C code. I have this script for an old Record Player in my horror game what it does is that it moves some parts ot it. (its an animation of the Record Player's arm and the disc rolling) That's not the problem, the script as it is works perfectly and plays the animation. I can choose from unity if i want the animation to play or not just by clicking on the box "Record Player Active" I simply want to add two things to this script. That this "animation" gets activated when the player is in the trigger of the object and presses "E" and stops playing when pressing "E" again (always beeing in the trigger) And the secod thing, that it plays music, i have the track but i dont know how to make it work:( If someone could send me the code with the solution it will help me a lot, i have been too long trying and always getting errors, im bad at #C This is the code: using UnityEngine; using System.Collections;

 public class RecordPlayer : MonoBehaviour {
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 
     public bool recordPlayerActive = false;
 
     GameObject disc;
     GameObject arm;
 
     int mode;
     float armAngle;
     float discAngle;
     float discSpeed;
 
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 void Awake()
 {
     disc = gameObject.transform.Find("teller").gameObject;
     arm = gameObject.transform.Find("arm").gameObject;
 }
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 void Start()
 {
     mode = 0;
     armAngle = 0.0f;
     discAngle = 0.0f;
     discSpeed = 0.0f;
 }
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 void Update()
 {
     //-- Mode 0: player off
     if(mode == 0)
     {   
         if(recordPlayerActive == true)
             mode = 1;
     }
     //-- Mode 1: activation
     else if(mode == 1)
     {
         if(recordPlayerActive == true)
         {
             armAngle += Time.deltaTime * 30.0f;
             if(armAngle >= 30.0f)
             {
                 armAngle = 30.0f;
                 mode = 2;
             }
             discAngle += Time.deltaTime * discSpeed;
             discSpeed += Time.deltaTime * 80.0f;
         }
         else
             mode = 3;
     }
     //-- Mode 2: running
     else if(mode == 2)
     {
         if(recordPlayerActive == true)
             discAngle += Time.deltaTime * discSpeed;
         else
             mode = 3;
     }
     //-- Mode 3: stopping
     else
     {
         if(recordPlayerActive == false)
         {
             armAngle -= Time.deltaTime * 30.0f;
             if(armAngle <= 0.0f)
                 armAngle = 0.0f;
 
             discAngle += Time.deltaTime * discSpeed;
             discSpeed -= Time.deltaTime * 80.0f;
             if(discSpeed <= 0.0f)
                 discSpeed = 0.0f;
 
             if((discSpeed == 0.0f) && (armAngle == 0.0f))
                 mode = 0;
         }
         else
             mode = 1;
     }
 
     //-- update objects
     arm.transform.localEulerAngles = new Vector3(0.0f, armAngle, 0.0f);
     disc.transform.localEulerAngles = new Vector3(0.0f, discAngle, 0.0f);
 }
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------------
 }
 
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 _Game_Dev_Dude_ · Nov 18, 2015 at 09:58 AM

I would not add them to this script I would create a new script. This new script would have to do 2 things:

  • It would have to be notified whenever a player enters the trigger you want.

  • it would then check in its update function if the player presses E.

Once both of these conditions are met, this script would toggle the recordPlayerActive bool in your current script and that should get it animating based on input.

As for the audio, just add some audio functionality to your record player code for when it is in the "Running" state and then ad Stop when it is in the Stopping phase.

http://docs.unity3d.com/ScriptReference/AudioSource.Play.html http://docs.unity3d.com/ScriptReference/AudioSource.Stop.html

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

28 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

Related Questions

I need help writing a script that triggers a character animation when entering a collider 0 Answers

Moving an Object to a random position 3 Answers

In my script the Animation selection pop up shows no assets even though i have several? 0 Answers

assign a new value to a variable 0 Answers

Move to next animation with clicking the game object 0 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