-
February 25th, 2014, 11:55 PM
#1
Question about c# in Unity 4.3.2
I am making a game for iphone and android and the screen scrolls at a certain speed and my character needs to jump from side to side to avoid objects. My question is once the score goes over a certain amount is it possible to increase the scroll speed? This is my current lines of code but they aren't working. Can someone please help a noob coder out =)
Code:
staticSpeed.scrollingSpeed = new Vector3 (0, -56, 0);//this is my scroll speed
{
if (scoreDisplayer.score > 100)
staticSpeed.scrollingSpeed = new Vector3 (0, -16, 0); //this should change speed when score reached 100+ but it doesnt =(
}
-
March 3rd, 2014, 12:46 PM
#2
Re: Question about c# in Unity 4.3.2
Anyone? If you need more code I can paste all of it, pleeeeease help. It's killing me
-
March 3rd, 2014, 02:30 PM
#3
Re: Question about c# in Unity 4.3.2
You are creating a new instance w/ new Vector3 (0, -16, 0);
Don't use NEW again
-
March 5th, 2014, 08:00 PM
#4
Re: Question about c# in Unity 4.3.2
I removed the "new" statement after the adjusted vector3 and its still not working, this time it gives me a "compiler error". I've included the whole script this time, maybe it'll help figure it out?
Code:
using UnityEngine;
using System.Collections;
//this script will instantiate new objects on gameplay
public class GameController : MonoBehaviour
{
// Use this for initialization
public GameObject[] objects;
public GameObject[] preloadParticles;
public float repeatTime = 3.0f;
public Camera UiCam;
void Start ()
{
staticSpeed.scrollingSpeed = new Vector3 (0, 0, 0);
//pre Load all the gameObjects and destroy them
foreach (GameObject a in objects) {
GameObject b = GameObject.Instantiate (a) as GameObject;
Destroy (b);
}
foreach (GameObject a in preloadParticles) {
GameObject b = GameObject.Instantiate (a) as GameObject;
Destroy (b);
}
staticSpeed.scrollingSpeed = new Vector3 (0, -49, 0);
if (scoreDisplayer.score > 100) staticSpeed.scrollingSpeed = new Vector3(0, -16, 0);
InvokeRepeating ("createNew", 1, repeatTime);//creates new objects for every repeatTime variable
}
void hideUiCam ()
{
UiCam.depth = -100;
Destroy (gameObject);
}
void createNew ()
{
if (player.health <= 0) {
Invoke ("hideUiCam", 0.5f);
return;
}
GameObject obj = GameObject.Instantiate (objects [Random.Range (0, objects.Length)]) as GameObject;
obj.transform.parent = transform;
}
// Update is called once per frame
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|