c# javascript calling

Hi all,

I’ve searched on this but am confused. I’m trying to use the original penelope examples but have the animation controller in js but camera relative in c# (I wish someone would make the whole tutorial in c# :frowning: ).

I’ve read about the order of directory compilation ; but I don’t see the directory structure for this anywhere.

I have just (as supplied with penelope):

Assets/audio

etc.etc.

Assets/scripts

Here I put all my .js and .cs files.
So where/how do I get the .js to compile first (animationcontroller) so that my c# will be ok with:

public AnimationController animationController ?

I’ve tried placing the .js file in Assets/Plugins with the .cs files in Assets/Scripts - but still no joy.

I must admit this is the most frustrating thing with the Unity tutorials; they are out of date (and don’t actually work) and are mostly in .js and not .js and .cs .

Any help always appreciated

thanks

Take a look at the Script Compilation Overview. Put what you want compiled first in a Standard Assets folder.

Hi,

Tried that, still no joy.
So I have

Assets/StandardAssets/script.js

and

Assets/Scripts/script.cs

The .cs script still doesn’t recognise the js class (script.js)

Can you see the problem?. I did read that compilation guide but can’t seem to get it to work.

Cheers

Has this been solved? I’m running on the very same problem here.

I have added an ‘AnimationController.cs’ C# translated from the original JavaScript and that problem goes away.
Here is the C# code if anybody cares:

using UnityEngine;
using System.Collections;

//////////////////////////////////////////////////////////////
// AnimationController.cs
// Penelope iPhone/Android Tutorial
//
// AnimationController plays the appropriate animations for Penelope
// and the blending between them. It uses the character’s
// movement direction to determine which animation should be played.
//////////////////////////////////////////////////////////////
public class AnimationController : MonoBehaviour {

// The Animation component that this script controls
public Animation animationTarget;

// Different speeds depending on movement direction
float maxForwardSpeed = 6;
float maxBackwardSpeed = 3;
float maxSidestepSpeed = 4;

private CharacterController character;
private Transform thisTransform;
private bool jumping = false;
private int minUpwardSpeed= 2;

void Start (){
// Cache component lookup at startup instead of doing this every frame
character = GetComponent< CharacterController >();
thisTransform = transform;

// Set up animation settings that aren’t configurable from the editor
animationTarget.wrapMode = WrapMode.Loop;
animationTarget[ “jump” ].wrapMode = WrapMode.ClampForever;
animationTarget[ “jump-land” ].wrapMode = WrapMode.ClampForever;
animationTarget[ “run-land” ].wrapMode = WrapMode.ClampForever;
animationTarget[ “LOSE” ].wrapMode = WrapMode.ClampForever;
}

void OnEndGame (){
// Don’t update animations when the game has ended
this.enabled = false;
}

void Update (){
Vector3 characterVelocity= character.velocity;

// When monitoring movement we check horizontal and vertical movement
// separately to decide what animations to play.
Vector3 horizontalVelocity = characterVelocity;
horizontalVelocity.y = 0; // ignore any vertical movement
float speed= horizontalVelocity.magnitude;

float upwardsMotion= Vector3.Dot( thisTransform.up, characterVelocity );

if ( !character.isGrounded upwardsMotion > minUpwardSpeed )
jumping = true;

if ( animationTarget.IsPlaying( “run-land” )
animationTarget[ “run-land” ].normalizedTime < 1.0f
speed > 0 )
{
// Let this animation finish
}
else if ( animationTarget.IsPlaying( “jump-land” ) )
{
// Let this animations finish
if ( animationTarget[ “jump-land” ].normalizedTime >= 1.0f )
// when the animation is done playing, go back to idle
animationTarget.Play( “idle” );
}
else if ( jumping )
{
if ( character.isGrounded )
{
// play the appropriate animation for landing depending on
// whether we are landing while running or jumping in-place
if ( speed > 0 )
animationTarget.Play( “run-land” );
else
animationTarget.Play( “jump-land” );
jumping = false;
}
else
animationTarget.Play( “jump” );
}
else if ( speed > 0 )
{
float forwardMotion= Vector3.Dot( thisTransform.forward, horizontalVelocity );
float sidewaysMotion= Vector3.Dot( thisTransform.right, horizontalVelocity );
float t= 0.0f;

// Use the largest movement direction to determine which animations to play
if ( Mathf.Abs( forwardMotion ) > Mathf.Abs( sidewaysMotion ) )
{
if ( forwardMotion > 0 )
{
// Adjust the animation speed to match with how fast the
// character is moving forward
t = Mathf.Clamp( Mathf.Abs( speed / maxForwardSpeed ), 0, maxForwardSpeed );
animationTarget[ “run” ].speed = Mathf.Lerp( 0.25f, 1, t );

if ( animationTarget.IsPlaying( “run-land” ) || animationTarget.IsPlaying( “idle” ) )
// Don’t blend coming from a land, just play
animationTarget.Play( “run” );
else
animationTarget.CrossFade( “run” );
}
else
{
// Adjust the animation speed to match with how fast the
// character is moving backward
t = Mathf.Clamp( Mathf.Abs( speed / maxBackwardSpeed ), 0, maxBackwardSpeed );

animationTarget[ “runback” ].speed = Mathf.Lerp( 0.25f, 1, t );
animationTarget.CrossFade( “runback” );
}
}
else
{
// Adjust the animation speed to match with how fast the
// character is side-stepping
t = Mathf.Clamp( Mathf.Abs( speed / maxSidestepSpeed ), 0, maxSidestepSpeed );

if ( sidewaysMotion > 0 )
{
animationTarget[ “runright” ].speed = Mathf.Lerp( 0.25f, 1, t );
animationTarget.CrossFade( “runright” );
}
else
{
animationTarget[ “runleft” ].speed = Mathf.Lerp( 0.25f, 1, t );
animationTarget.CrossFade( “runleft” );
}
}
}
else
// Play the idle animation by default
animationTarget.CrossFade( “idle” );
}
}

You can try putting your scripts in either an
Plugins
folder or a
Editor
folder. I believe the link posted earlier will tell you the same thing.

For sharing a data class between the two scripts. I’ve made a C# class that contains everything and placed it in the plugins folder.
then my Monobehaviour derivatives (scripts i wrote to be placed on unity objects in the game world) have the data object inside of them defined. This was the only way to cross languages with unity in my experiences.
IE:

// anywhere in unity and attached to a game object.
public class something : Monobehaviour
{
     public DataClass dc = null;
}

// inside my plugin folder
namespace MyNamespace.Data
{
public class DataClass
{
     public string userName = "garfield";
     public float weight = 211.0f;
}
}

This is kind of an advanced topic for someone passing thru tutorials though.

Ok. Thanks for that superfast answer. I’ve done DataClasses to store strings on many languages too.
Good trick using it to call other scripts too. Thx again.