The more this tutorial, the more frustrated I am getting. The latest issue comes from teh targeting script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Targeting : MonoBehaviour {
public List<Transform> targets;
public Transform selectedTarget;
private Transform myTransform;
// Use this for initialization
void Start () {
targets=new List<Transform>();
AddAllEnemies();
selectedTarget=null;
myTransform= transform;
}
public void AddAllEnemies() {
GameObject[] go=GameObject.FindGameObjectsWithTag("Enemy");
foreach(GameObject Enemy in go)
AddTarget(Enemy.transform);
}
public void AddTarget(Transform Enemy) {
targets.Add(Enemy);
}
private static int SortTargetsbyDistance(Transform t1, Transform t2) {
return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position));
}
private void TargetEnemy()
{
if (selectedTarget == null)
{
SortTargetsbyDistance();
selectedTarget=targets[0];
}
else
{
int index= targets.IndexOf(selectedTarget);
if (index < targets.Count -1)
{
index ++;
}
else {
index=0;
}
DeselectTarget();
selectedTarget=targets[index];
}
SelectTarget();
}
private void SelectTarget(){
selectedTarget.renderer.material.color=Color.red;
PlayerAttack pa= (PlayerAttack)GetComponent("PlayerAttack");
pa.target= selectedTarget.gameObject;
}
private void DeselectTarget() {
selectedTarget.renderer.material.color=Color.blue;
selectedTarget=null;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Tab)){
TargetEnemy();
}
}
}
it seems to be having trouble with the myTranform variable. I double checked to make sure myTransform = transform instead of Transform, but now it’s having trouble with the returning transform position.
Assets/Scripts/Targeting.cs(34,42): error CS0120: An object reference is required to access non-static member `Targeting.myTransform’
Assets/Scripts/Targeting.cs(34,20): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Distance(UnityEngine.Vector3, UnityEngine.Vector3)’ has some invalid arguments
Assets/Scripts/Targeting.cs(34,20): error CS1503: Argument #2' cannot convert object’ expression to type `UnityEngine.Vector3’
Assets/Scripts/Targeting.cs(43,25): error CS1501: No overload for method SortTargetsbyDistance' takes 0’ arguments
What am I missing here?
Also still having issues with the basecharacter script.
I narrowed it down to the setup vitals section and lines of this type:
GetVital=((int)VitalName.Life).AddModifer( new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution ), .5f));
It can’t seem to find the variable that’s under its nose. Is there another way to do this?
Thanks!