public class NonSpellFairyControl : MonoBehaviour {
public float Speed;
public GameObject FairyBullet;
Vector2 topRightConner = new Vector2(10.2f, 4.9f);
Vector2 bottomLeftConner = new Vector2(-10, -4.9f);
float[] BulletPath = new float[] { 22.5f, 45.0f, 67.5f, 90f, 112.5f, 135f, 157.5f, 180f, 202.5f, 225f, 247.5f, 270f, 292.5f, 315f, 337.5f, 360f};
public static float BulletDirection;
// Use this for initialization
void Start ()
{
GameObject boss = GameObject.Find("Alice");
if (gameObject.transform.position.x < boss.transform.position.x)
{
Speed = -Speed;
}
InvokeRepeating("ShootBullet", 0.1f, 1f);
}
// Update is called once per frame
void Update ()
{
gameObject.transform.Translate(Speed * Time.deltaTime, 0, 0);
}
void ShootBullet()
{
GameObject Bullet1 = Instantiate(FairyBullet);
BulletDirection = BulletPath[0];
Bullet1.transform.Rotate(0, 0, DeterMineBulletRotation(BulletPath[0]));
}
float DeterMineBulletRotation(float TravelDirectionDegree)
{
// When Rotate respect to Z asxis 0 degrees is corsponding to 90 degrees in normal sense, and 0 degrees in UnitCircle is -90 in this case
float rotationDegres;
rotationDegres = -90f + TravelDirectionDegree;
return rotationDegres;
}
}
So I set the static field BulletDirection to 22.5 in this case in the spawner, the bullet does get the 22.5 from this script and it does show 22.5 everytime in Debug.log but instead translate in 22.5degree postive it trnslate 22.5 degrees negative.
Here is the code in the bullet script
public class NonSpellFairyBulletControl : MonoBehaviour {
public float Speed;
float BulletPath;
Vector3 UnitVector;
// Use this for initialization
void Start ()
{
BulletPath = NonSpellFairyControl.BulletDirection;
Debug.Log(BulletPath);
BulletPath = Mathf.Deg2Rad * BulletPath;
UnitVector = new Vector3(Mathf.Cos( BulletPath), Mathf.Sin(BulletPath) , 0);
}
// Update is called once per frame
void Update ()
{
gameObject.transform.Translate(Speed * Time.deltaTime * UnitVector.x, Speed * Time.deltaTime * UnitVector.y , 0);
}
}
This is the scene while the game play, why the bullet doesn’t translate on 22.5degree postive(Green Arrow) path?
