I’m making a Space Invaders clone as a learning exercise (Unity beginner here).
When I press fire I want a shot to appear at the player’s position of course (I haven’t got to making the shot travel yet).
At the moment when I press fire the ‘playerShot’ appears in the centre of the screen, not where the player is.
What am I doing wrong? The script is attached to the player object and so it should inherit the default position and rotation of the player shouldn’t it?
The only idea I had was maybe it’s an issue because I’m using Orthello2D? I was thinking of making my objects sprites rather than rigid bodies because I thought that would be more efficient. Am I wrong?
Code below. Any help much appreciated.
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
//Figure used to change speed of left/right movement
public float moveSpeed = 400.0f;
public GameObject playerShot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Setting variables and defining basic left/right player movement
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
transform.Translate(h, 0, 0);
//Fire mechanism
if (Input.GetButtonUp("Fire1")){
OTSprite newPlayerShot = Instantiate (playerShot, transform.position, transform.rotation) as OTSprite;
}
}
}