Hello, new Unity user here. New to javascript as well. I am pretty good with Game Maker, but decided to upgrade my video game creating experience. I am very impressed with Unity. Anyways, on to the question. I was following the Lorax’s old tutorial about concept to video game video tutorials, where he makes a simple cube and 2 spheres and makes a top down scrolling shooting game. Well, I decided to try to expand upon it, and make it so that if the user pushes “1” on the keyboard, the “var playerWeapon” = 1, and “2” makes “playerWeapon = 2” … I did a “print” test, and the code works fine for those. The question is, when playerWeapon = 2, I want to create 2 bullet instances, but I keep getting errors. What am I doing wrong? Here is my code.
// fire weapon
if( Input.GetKeyDown(“space”))
{
var tempBullet: Rigidbody;
if (playerWeapon = 1) // if playerWeapon = 1, create 1 bullet in center of player
{
tempBullet = Instantiate(bullet, transform.position, transform.rotation)
}
if (playerWeapon = 2) // if playerWeapon = 2, create 2 bullets on side of player
{
tempBullet = Instantiate(bullet, transform.position.x - .05, transform.rotation)
tempBullet = Instantiate(bullet, transform.position.x + .05, transform.rotation)
}
}
I should probably note, I’m getting 3 errors, lines 51,26 51,28 and 53,28 line 51 is the line
if (playerWeapon = 1) // if playerWeapon = 1, create 1 bullet in center of player
and line 53 is
tempBullet = Instantiate(bullet, transform.position, transform.rotation)