CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2014
    Posts
    3

    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 =(
    		
    	}

  2. #2
    Join Date
    Feb 2014
    Posts
    3

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2014
    Posts
    3

    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
  •  





Click Here to Expand Forum to Full Width

Featured