- Home /
Problem With Rotation Speed and Problem With Audio
I have been following a Udemy guide to Unity: https://www.udemy.com/become-a-game-designer/
It has its problems with being up to date, but I have been able to solve most of them until now. First off the rotation speed doesn't change even if I change it from 20.0f to 100.0f.
Here's the code: https://pastebin.com/KYUKy67S
Fixed code: https://pastebin.com/4Q4kQMeZ
The other problem is with sound. It gives me an error saying this: Assets/Scripts/TriggerEvent.cs(18,10): error CS1061: Type UnityEngine.Component' does not contain a definition for
PlayOneShot' and no extension method PlayOneShot' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
Here's the code for that: https://pastebin.com/A2PYHg7m
Fixed code: https://pastebin.com/7P4S3DgW
I'm pretty new to Unity and I don't know how to solve this. Thanks in advance.
Answer by Xysch · Feb 26, 2018 at 07:10 PM
In the first code you never used the rotationSpeed variable, you used speed and -speed instead of rotationSpeed in your rotate function. For the audio one I'm not too familiar with audio but it seems you didn't assign anything named audio or PlayOneShot. Hope this helps!
I have no idea how I missed that. Thank you! I'm not at all familiar with PlayOneShot but I'm pretty sure my code matches the instructor's code in the videos. I'll check but I think the second one has to do with his code being outdated.
Answer by Chik3r · Feb 26, 2018 at 08:00 PM
Hi @connoradams251
For your problem with playOneTime: First your object must have an audioSource attached or have a reference to a source in the scene. Then you must give it a reference to a clip. Then you must call PlayOneShot which is in the audioSource with the following args: 1. Required: The clip to play. 2. Optional: The volume scale. And thats it!
I've fixed all errors other than this one:
Assets/Scripts/TriggerEvent.cs(39,10): error CS1061: Type UnityEngine.Component' does not contain a definition for
Stop' and no extension method Stop' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
I have fixed this error. Thank you for the help!