(sorry for not following the law for thread-naming )
When trying to create my small piano game, I have stumbled upon a number of problems which I could not solve. Spending many hours trying to resolve each one, I could not. For this reason, I humbly refer to you for any help you can give on these matters:
How would I move an object smoothly (speeds up for 1 second, 1 second flight, slows down for 1 second etc.) from one point (or current position) to another defined in vector3 3D space? I know that this had been asked to death in the past, but no solution works for meā¦
Where āpressedā is the value returned. This is read by an āif (pressed == 1)ā (1 being the first button etc.) in another script inside an update function. I truly donāt know whether this is the ultimate method :-|, but aside of that, once the button is pressed, it returns its value two times (āaaā instead of āaā etc.). I would greatly appreciate any help with this.
Is there any way to assign a single audio source onto multiple objects? Unity seems to only accept one object per source, which forces me to create hundreds of audio sources for the keys of a pianoā¦
So, um⦠I think thatās it so far. I truly hope that somebody will be able to answer these⦠And thank in advance. These things have taken up hours of my time, and I simply was unable to solve them. Again, thanks.
Answering all of these in detail would take a long time and really depends on your specific setup and needs (both now and future), so they are hard to answer. But here are some thoughts:
Use iTween - google it if you are not aware of it, but it is a set of static methods that you can call that allow for dynamic actions on an object (such as moving, rotating, fading, etcā¦).
There are many ways to implement this and the best way will vary from project to project. You could have one āKeyManagerā script attached to a parent object to the keys which manages the keys (in itās Start() you could find all the keys to be used, or you could have the keys as a public array var on this object and then drag them in the inspector as examples). Or the keys could simply do a āSendMessageā up to the parent object and the Manager could receive these calls and act appropriately depending on the key that fired.
Best way I can think of would be to create a pool of audiosources (creating the maximum that could be used at once) and as keys are pressed you can pull them from the pool, use them and put them back. This is known as caching and has a heavier memory footprint but lighter cpu footprint than creating and destroying them on the fly. It also saves you from creating one per key.
Ah, thank you. I apologise for not replying for a long time.
So⦠iTween⦠It appears to be commercial. Right now I have much more experience with JavaScript, and might actually pull it off with Lerp⦠Ok then.
No, still does not work. No errors. Just nothing happens. The thread you mentioned did not help by much, but I will try to figure it out. Thanks.
Finally got the thing to work! Thank you. Now struggling with generating a password correctly.
The example is for speeding up, for slowing down I guess you will have to do something similar but reverse.
I re-wrote the code a little to make it easier to read.
var maxSpeed = 20.0; // Max Speed!
var accelerationSpeed = 5.0; // This is the speed to accelerate per second
function Update() {
transform.position = Vector3(Mathf.MoveTowards (transform.position.x, maxSpeed, accelerationSpeed * Time.deltaTime), 0, 0);
}
Note that this code will move the Transform by the X position only. so you will have to modify that i guess.