hey
got this script where i want to change the amount according to levels of player score.
it’s not working a 100% atm which i think is because of the
if(playerscript.playerScore >= 1000) {amount=…
and then
if(playerscript.playerScore >= 5000){amount=…
I think the amount should be set only if the playerScore is between 1000 5000, so i would like to use a Mathf.Clamp… only i don’t get it in the right way.
I’m no programmer so it can take a long time just to get it working with copy/paste, trail and error, the way i did the rest of the script
any suggestions are welcome
the Mathf.Clamp is where i thought it would work, which it didn’t… the other scores is the way it was before which work a little bit… meaning my other firing script destorys at score 1000 and this one started working but only made one chance and didn’t change a thing when reaching 5000…
var projectile : GameObject;
var amount : int;
function Update () {
if( Input.GetButtonUp( "Jump" ) )
{
if(playerscript.playerScore = Mathf.Clamp (playerscript.playerScore, 1000, 5000)) {
amount= 2;
for (var i = 0; i <= amount; i++){
var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
if(playerscript.playerScore>=5000){
amount= 3;
for ( i = 0; i <= amount; i++){
Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
if(playerscript.playerScore>=10000){
amount= 4;
for ( i = 0; i <= amount; i++){
Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
}
}
update, this works for the faseOne, but at faseTwo i get a null reference exception at line 24…?
var projectile : GameObject;
var amount : int;
function Update () {
if( Input.GetButtonUp( "Jump" ) )
{
var faseOne = Mathf.Clamp (playerscript.playerScore, 1000, 2500);
if(playerscript.playerScore == faseOne){
amount= 1;
for (var i = 0; i <= amount; i++){
var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
var faseTwo = Mathf.Clamp (playerscript.playerScore, 2500, 5000);
if(playerscript.playerScore==faseTwo){
amount= 2;
for ( i = 0; i <= amount; i++){
instantiatedProjetile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
if(playerscript.playerScore>=10000){
amount= 3;
for ( i = 0; i <= amount; i++){
instantiatedProjetile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
}
}
well should anyone need it this version works fine
var projectile : GameObject;
var amount : int;
var instantiatedProjectile : GameObject;
function Update () {
if( Input.GetButtonUp( "Jump" ) )
{
var faseOne = Mathf.Clamp (playerscript.playerScore, 1000, 2500);
if(playerscript.playerScore == faseOne){
amount= 1;
for (var i = 0; i <= amount; i++)
{
instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
var faseTwo = Mathf.Clamp (playerscript.playerScore, 2500, 5000);
if(playerscript.playerScore==faseTwo){
amount= 2;
for ( i = 0; i <= amount; i++)
{
instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
var faseThree = Mathf.Clamp (playerscript.playerScore, 5000, 10000);
if(playerscript.playerScore==faseThree){
amount= 3;
for ( i = 0; i <= amount; i++)
{
instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
var faseFour = Mathf.Clamp (playerscript.playerScore, 10000, 15000);
if(playerscript.playerScore==faseFour){
amount= 4;
for ( i = 0; i <= amount; i++)
{
instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
var faseFive = Mathf.Clamp (playerscript.playerScore, 15000, 50000);
if(playerscript.playerScore==faseFive){
amount= 5;
for ( i = 0; i <= amount; i++)
{
instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.transform.eulerAngles = Vector3( (-30)+(60/amount*i), 0, 0);
}
}
}
}