Scripting documentation

0
portapipe posted this 02 May 2016

It should be a cool idea to have a wiki documentation (like github) to avoid any questions about basic scripting.

For example I need to play a single time an animation (a trampoline animation on triggering a collider) and I really don't know how to do it after an hour of deep googling.

Any advise on how to do that? There is a way to implement any code in Javascript?

The PicaVoxel classes are not so much, a wiki with some examples will really help us :)

10 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 02 May 2016

Hi,

The BasicAnimator included with PicaVoxel doesn't have a non-looping mode, which is probably why you couldn't figure out how to play the animation just once.

I have a new version of the animator for you that allows you to set whether or not to loop the animation. You will need to replace the code in PicaVoxel/Scripts/BasicAnimator.cs and PicaVoxel/Scripts/Editor/BasicAnimatorEditor.cs with the code from the following Gist:

https://gist.github.com/GarethIW/4feac837044196bb2058945c400a1d2b

Assuming you have the following:

  1. A PicaVoxel Volume for your trampoline
  2. An animation set up on the trampoline as outlined in the PicaVoxel manual
  3. A BasicAnimator script attached
  4. Your own script for controlling the trampoline

First, set the BasicAnimator to non-looping and not play on awake:

enter image description here

Then, to play the animation when something collides with the trampoline, you would add the following to your own script:

public void OnCollisionEnter(Collision collision)
{
    GetComponent<basicanimator>().Play();
}

Hope that helps!

0
portapipe posted this 02 May 2016

What can I say... Great! Thanks! I'll test it in a couple of days. Can I use that in a JavaScript file?

0
GarethIW posted this 02 May 2016

I'm not familiar with using JavaScript in Unity, but a quick search says the equivalent line of code would be something like:

this.GetComponent("BasicAnimator").Play();

But I've also read that you may need to do something with compilation order to make sure the C# compiles before the JavaScript. You could try moving the PicaVoxel folder to a folder named Plugins in the root of your project.

You might need to do some googling for "unity call C# method from JavaScript" or something similar.

0
portapipe posted this 02 May 2016

Oh great, that will be useful! If I'll use some of the PicaVoxel code I can help you with making a wiki code documentation if you need to.

Last edited 02 May 2016

0
portapipe posted this 04 May 2016

Hi, I have time now to test the new animation stuff. The loop works fine but just on play. If I choose to not loop on the editor and I Play the game he forget the non-loop flag. enter image description here

Last edited 04 May 2016

0
GarethIW posted this 04 May 2016

I can't think of a reason for that to be happening. Do you get the same behaviour for Ping pong and/or Random start frame?

Did you try turning off Play on Awake?

0
portapipe posted this 04 May 2016

I've tried to disable all but Loop and Play on Awake remain toggled on, even if I choose Ping pong... it stay alway with loop and Play on Awake selected and nothing else... I've read the code and it's very odd... If you have an IRC channel we can chat there and fix that.

Last edited 04 May 2016

0
GarethIW posted this 04 May 2016

I don't have any helpful suggestions at this point, I don't have this problem with Unity 5.3.4f1. There is something going wrong with the serialization between edit and play modes.

What version of Unity are you running? And what OS?

Did you end up having to move PicaVoxel to the Plugins folder to get it working with JS?

0
portapipe posted this 04 May 2016

The JS stuff is waiting for a working animation script, and the one you've posted is fine. I just had to remove then reimport the animation script into the trampoline inspector, that's it :)

Now I think will work (plus if you, reader, have the same issue you know now how to fix it :) )

Thanks Gareth. Let me know about the wiki. I think I'll use lots of the common stuff PicaVoxel has (but in javascript).

Have a nice day :)

0
portapipe posted this 04 May 2016

Oh, just to be complete, here's the code I've use for my trampoline animation in Javascript :)

And... yes, the PicaVoxel folder MUST be moved to a Assets/Plugins folder to make it work properly.

#pragma strict

var animator : PicaVoxel.BasicAnimator;
function Start () {
    animator = this.GetComponent("PicaVoxel.BasicAnimator");
}
function OnTriggerEnter(other : Collider)
{
    animator.Play();
}

Last edited 04 May 2016


Our 123 members have posted 456 times in 110 discussions