The title says it all. I’m using AngryAnts Behave 1.3 along with agre systems demo with the use of the behave system but as soon as I import everything into the project file that error pops up. I’ve been trying to figure it out all day. I’m no programmer that’s why I follow the tutorial that doesn’t seem to want to work. So if someone could tell me what the problem is it would make my job alot easier. Thank you!
The error pops up right after MonoBehaviour for “Agent”
using UnityEngine;
using System.Collections;
using BehaveLibrary;
public class BallKicker : MonoBehaviour, Agent
{
#region Public properties
public float speed = 5.0f;
#endregion
#region Private properties
// Object we will pursue
private GameObject ball;
// We will always store the current action, so that the Update method can
// perform whatever animation code is necessary
BLBallKickerLibrary.Actions currentAction;
Tree actionTree;
private bool hitBall = false;
private bool canSeeBall = false;
private float speedFactor = 0.0f;
private float restSeconds = 2.0f;
private float timeLastAction = 0.0f;
#endregion
// Use this for initialization
void Start () {
// Every kicker has a slightly different speedFactor
speedFactor = Random.Range(0.6f, 1.0f);
// We're not performing any actions, are we?
currentAction = BLBallKickerLibrary.Actions.Unknown;
actionTree = BLBallKickerLibrary.Instance.Tree((int) BLBallKickerLibrary.Trees.Kicker_BallChaser);
ball = GameObject.FindWithTag("Ball");
}
void FixedUpdate () {
if( actionTree.Tick( this, null ) != BehaveResult.Running )
{
actionTree.Reset( this, null );
}
}
// Update is called once per frame
void Update () {
switch(currentAction)
{
case BLBallKickerLibrary.Actions.WaitForBall:
transform.renderer.material.color = Color.green;
break;
case BLBallKickerLibrary.Actions.RestAfterKick:
transform.renderer.material.color = Color.blue;
break;
case BLBallKickerLibrary.Actions.GoToBall:
transform.renderer.material.color = Color.red;
Vector3 translate = ball.transform.position - transform.position;
transform.Translate(translate.normalized * speedFactor * speed * Time.deltaTime, Space.World);
break;
}
}
#region Agent methods
public BehaveResult TickAction( int action, Tree sender, Object data )
{
switch( ( BLBallKickerLibrary.Actions )action )
{
case BLBallKickerLibrary.Actions.WaitForBall:
return WaitForBall();
case BLBallKickerLibrary.Actions.GoToBall:
return GoToBall();
case BLBallKickerLibrary.Actions.KickBall:
return KickBall();
case BLBallKickerLibrary.Actions.RestAfterKick:
return Rest();
}
return BehaveResult.Failure;
}
public void ResetAction( int action, Tree sender, Object data )
{
hitBall = false;
}
public BehaveResult TickDecorator( int decorator, Tree sender, Object data )
{
// We'll go over this guy in another tutorial
return BehaveResult.Success;
}
public void ResetDecorator( int decorator, Tree sender, Object data )
{
// We'll go over this guy in another tutorial
}
#endregion // Agent methods
#region Collider events
public void OnCollisionEnter (Collision collisionInfo)
{
// We will have found the ball once we have collided with it
if (collisionInfo.gameObject == ball)
hitBall = true;
}
public void OnCollisionStay (Collision collisionInfo)
{
// We will have found the ball once we have collided with it
// We evaluate OnCollisionStay was well just in case the
// random force applied wasn't strong enough to move it away
// from this object.
if (collisionInfo.gameObject == ball)
hitBall = true;
}
public void OnTriggerEnter(Collider other)
{
// The trigger is used for ball proximity detection
if (other.gameObject == ball)
{
canSeeBall = true;
}
}
public void OnTriggerExit(Collider other)
{
// The trigger is used for ball proximity detection. If this fires,
// the ball has moved outside our detection area
if (other.gameObject == ball)
{
canSeeBall = false;
}
}
#endregion
#region Action handling methods
BehaveResult WaitForBall()
{
BehaveResult result = BehaveResult.Failure;
if (ball == null)
{
Debug.Log("A ball should have been assigned");
}
else if (canSeeBall)
{
// We were waiting for the ball to enter our viewing area so we can
// go in and kick it. Move on to the next action!
result = BehaveResult.Success;
}
else
{
/*
We don't have a ball nearby, so just wait until one lands close
to us.
BehaveResult.Running indicates to the library that the current
action is still executing.
*/
currentAction = BLBallKickerLibrary.Actions.WaitForBall;
result = BehaveResult.Running;
}
return result;
}
/* This action will return Success once we're close enough to the ball for kicking,
and Running meanwhile. While the action is Runnning, our Update method will
keep moving us closer.
*/
BehaveResult GoToBall()
{
BehaveResult result = BehaveResult.Running;
// Since WaitForBall evaluates that we do have a ball object assigned,
// we can safely assume that one exists if we got this far.
if (hitBall)
{
// We have collided with the ball - stop moving
hitBall = false;
result = BehaveResult.Success;
currentAction = BLBallKickerLibrary.Actions.Unknown;
}
else
// Tell Update we're still executing
currentAction = BLBallKickerLibrary.Actions.GoToBall;
return result;
}
BehaveResult KickBall()
{
// Apply a random force to the ball. We're a horrible kicker.
Vector3 v = Random.insideUnitSphere;
v.y = Mathf.Abs(v.y);
v *= 1000;
Vector3 forcePos = Random.insideUnitSphere;
ball.rigidbody.AddForceAtPosition(v, forcePos);
// Every time we kick the ball, our speedFactor changes again, to mix
// things up a bit
speedFactor = Random.Range(0.2f, 2.0f);
timeLastAction = Time.time;
Debug.Log("Kicked! " + transform.GetInstanceID() + " " + speedFactor);
// Once the force has been applied, return successfully. This is
// a one-shot action.
return BehaveResult.Success;
}
// Each kicker had to rest a certain number of seconds after hitting the ball
BehaveResult Rest()
{
if (Time.time - timeLastAction < restSeconds)
{
currentAction = BLBallKickerLibrary.Actions.RestAfterKick;
return BehaveResult.Running;
}
else
{
currentAction = BLBallKickerLibrary.Actions.Unknown;
return BehaveResult.Success;
}
}
#endregion
}
May I ask why I probably get this message when I try to change a variable in a .js script on one object, from a .cs script on another object? Is it maybe related to what you mentioned? Edit: Thank you so much, it was your advice, which led me to the right path! I had to put the .js into the Standard Assets folder, in order to compile first.
– dot_entity