04-09-2014, 12:53 PM
(04-09-2014, 11:16 AM)LatinMan Ha scritto: grazie mille,ho risolto
però è nato un'altro problema ,riguarda un'altro script che ha come base quello dell'altra volta....eccolo:
Codice:using UnityEngine;
using System.Collections;
public class WeaponScript : MonoBehaviour
{
public Weapon[] Weapons;
public Weapon Currentweapons;
public float AimSpeed;
[HideInInspector]
private Vector3 normalPosition;
private float endFire;
void Start ()
{
EnableWep(0);
}
void Update ()
{
if (Input.GetMouseButton(0))
{
Fire();
}
if (Input.GetMouseButton(1))
{
Aim();
}
else
{
Currentweapons.wepTrasform.localPosition = Vector3.Lerp(Currentweapons.wepTrasform.localPosition, normalPosition, Time.deltaTime * AimSpeed);
}
if(Input.GetKey(KeyCode.R))
{
Currentweapons.wepTrasform.animation.Play(Currentweapons.ReloadAnim);
}
}
void EnableWep(int nun)
{
Currentweapons = Weapons[nun];
Currentweapons.wepTrasform.animation.Play(Currentweapons.DrawAnim);
normalPosition = Currentweapons.weptrasform.LocalPosition;
}
void Fire()
{
if (endFire < Time.time)
{
endfire = Time.time + Currentweapons.fireRate;
if (Currentweapons.wepTrasform.animation.isPlaying(Currentweapons.FireAnim))
{
Currentweapons.wepTrasform.animqtion.Rewind(Currentweapons.FireAnim);
}
Currentweapons.wepTrasform.animation.Play(Currentweapons.FireAnim);
}
}
void Aim()
{
Currentweapons.wepTrasform.localPosition = Vector3.Lerp(Currentweapons.wepTrasform.localPosition,new Vector3(Currentweapons.positionzoomed, Currentweapons.positionzoomed, Currentweapons.positionzoomed));
}
}
[System.Serializable]
public class Weapons
{
public string name;
public Transform wepTrasform;
public string DrawAnim, FireAnim, ReloadAnim;
public int Damage;
public float PositionXzoomed , PositionYzoomed , PositionZzoomed;
public float FireRate;
}
oggi ho controllato un milone di volte se ho sbagliato qualcosa...lo script dovrebbe essere scritto così...maiuscole/minuscole e gli spazi penso che siano tutti messi bene.
ecco l'erroe:
Assets/Scripts/WeaponScript.cs(6,16): error CS0246: The type or namespace name `Weapon' could not be found. Are you missing a using directive or an assembly reference?
Assets/Scripts/WeaponScript.cs(7,16): error CS0246: The type or namespace name `Weapon' could not be found. Are you missing a using directive or an assembly reference?
Prova così, praticamente la classe Weapon che avevi creato la hai chiamata "Weapons", mentre la variabile si chiamava Weapon. Ho soltanto cacciato la "s" dal nome della classe,quindi da "Weapons" lo rinominata in "Weapon", quando tu crei la variabile "Weapon" ti riferisci alla classe creata in precedenza quindi i nomi devono coincidere, spero d'essere stato d'aiuto .
Codice:
using UnityEngine;
using System.Collections;
public class WeaponScript : MonoBehaviour
{
public Weapon[] Weapons;
public Weapon Currentweapons;
public float AimSpeed;
[HideInInspector]
private Vector3 normalPosition;
private float endFire;
void Start ()
{
EnableWep(0);
}
void Update ()
{
if (Input.GetMouseButton(0))
{
Fire();
}
if (Input.GetMouseButton(1))
{
Aim();
}
else
{
Currentweapons.wepTrasform.localPosition = Vector3.Lerp(Currentweapons.wepTrasform.localPosition, normalPosition, Time.deltaTime * AimSpeed);
}
if(Input.GetKey(KeyCode.R))
{
Currentweapons.wepTrasform.animation.Play(Currentweapons.ReloadAnim);
}
}
void EnableWep(int nun)
{
Currentweapons = Weapons[nun];
Currentweapons.wepTrasform.animation.Play(Currentweapons.DrawAnim);
normalPosition = Currentweapons.weptrasform.LocalPosition;
}
void Fire()
{
if (endFire < Time.time)
{
endfire = Time.time + Currentweapons.fireRate;
if (Currentweapons.wepTrasform.animation.isPlaying(Currentweapons.FireAnim))
{
Currentweapons.wepTrasform.animqtion.Rewind(Currentweapons.FireAnim);
}
Currentweapons.wepTrasform.animation.Play(Currentweapons.FireAnim);
}
}
void Aim()
{
Currentweapons.wepTrasform.localPosition = Vector3.Lerp(Currentweapons.wepTrasform.localPosition,new Vector3(Currentweapons.positionzoomed, Currentweapons.positionzoomed, Currentweapons.positionzoomed));
}
}
[System.Serializable]
public class Weapon
{
public string name;
public Transform wepTrasform;
public string DrawAnim, FireAnim, ReloadAnim;
public int Damage;
public float PositionXzoomed , PositionYzoomed , PositionZzoomed;
public float FireRate;
}