- Home /
i am pretty sure that this is right but.....
the problems are (5,9)CS1519 and (11,9)CS1525
code:
using UnityEngine;
using System.Collections;
public class Skellyattack : MonoBehaviour {
public GameObject player;
public GameObject skelly;
public float distance;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
player = GameObject.find ("Player");
skelly = GameObject.Find ("skeleton");
distance = Vector3.Distance(player.transform.position. skelly.transform.postion);
if (distance <= 3) {
skelly.animation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
}
else if(distance < 15 && Distance > 5.0f){
skelly.animation.CrossFadeQueued("attack", 0.3f. QueueMode.PlayNow);
skelly.animation.CrossFade("run");
skelly.transform.LookAt(player.transform.position);
skelly.transform.postion = Vector3.MoveTowards(skelly.transform.postion, player.transform.position);
}
else
{
skelly.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
skelly.CrossFade("idle");
}
}
}
Answer by Eric5h5 · Jan 01, 2015 at 06:08 PM
Pro tip: when Unity gives you an error message, Unity is correct and you are wrong.
Answer by RudyTheDev · Dec 31, 2014 at 05:03 PM
You really need to be able to debug and solve syntax errors yourself if you want to learn game development properly. Otherwise, you will get stuck a lot. The errors here are very obvious (besides MoveTowards
speed). You should also be posting the full error message and explaining the steps you have taken to solve it yourself. Most of these errors have been answered many, many time before, if you do a quick search beforehand. And do try to format your code properly. Anyway:
using UnityEngine;
using System.Collections;
public class Skellyattack : MonoBehaviour
{
public GameObject player;
public GameObject skelly;
public float distance;
public float speed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
player = GameObject.Find("Player");
skelly = GameObject.Find("skeleton");
distance = Vector3.Distance(player.transform.position, skelly.transform.position);
if (distance <= 3)
{
skelly.animation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
}
else if (distance < 15 && distance > 5.0f)
{
skelly.animation.CrossFadeQueued("attack", 0.3f, QueueMode.PlayNow);
skelly.animation.CrossFade("run");
skelly.transform.LookAt(player.transform.position);
skelly.transform.position = Vector3.MoveTowards(skelly.transform.position, player.transform.position, speed);
}
else
{
skelly.animation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
skelly.animation.CrossFade("idle");
}
}
}
when I run the game it says:
$$anonymous$$issingComponentException: There is no 'Animation' attached to the "skeleton" game object, but a script is trying to access it. You probably need to add a Animation to the game object "skeleton". Or your script needs to check if the component is attached before using it. UnityEngine.Animation.CrossFadeQueued (System.String animation, Single fadeLength, Queue$$anonymous$$ode queue) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Animations.cs:613) Skellyattack.Update () (at Assets/Skellyattack.cs:36)
Ok, and what do you think that error message might mean...?
Your answer
![](https://koobas.hobune.stream/wayback/20220613175306im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Looking for Code that will Read JSON files (C# code) 2 Answers
Iterating through multidimensional arrays 2 Answers
Simple Data Parsing from Text Files 1 Answer