I have 2 scripts that have errors I have never encountered before,
the first script makes an animated character wander around an object, the errors are occurring in line 7-14
using UnityEngine;
using System.Collections;
public class RandomWander : MonoBehaviour {
public GameObject init;
private Transform initpos = init.GetComponent();
private float time = 10;
private boolean update = true;
public float radius;
float lowX = initpos.x - radius;
float highX = initpos.x + radius;
float lowZ = initpos.z - radius;
float highZ = initpos.z + radius;
// Use this for initialization
void Start () {
anim = gameObject.GetComponent ();
}
// Update is called once per frame
void Update () {
if (update) {
Vector3 pos = getRandomPos();
}
gameObject.LookAt(pos);
if (gameObject.transform.position == pos){
time -= Time.deltaTime;
anim.SetBool("Walking", false);
if (time <= 0.0f){
update = true;
time = 10.0f;
}
} else {
transform.position += transform.forward * 0.2f;
anim.SetBool("Walking", true);
}
}
Vector3 getRandomPos(){
Vector3 pos;
pos.x = Random.Range(lowX, highX);
pos.y = initpos.y;
pos.z = Random.Range(lowZ, highZ);
return pos;
}
}
Second script allows the FPS controller to attack these NPC's but there are errors with line 22 and 29
using UnityEngine;
using System.Collections;
public class SwordAttack : MonoBehaviour {
public int frame = 0;
public GameObject sword;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//replace with left key check
if (Input.GetMouseButtonDown(0) && frame <= 10){
sword.transform.position += sword.transform.forward*0.1f;
++frame;
} else if (frame >= 11){
frame = 0;
sword.transform.position += sword.transform.back*0.1f*frame;
}
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "Enemy"){
other.gameObject.GetComponent().SetBool("Dead", true);
}
}
}
If anybody can resolve these issues it would be greatly appreciated.
↧