Skip to main content

Posts

Showing posts with the label JavaScript

A Few Pointers On Switching From JavaScript To C#

One does not simply add to an array. In JavaScript you might have familiarity with using arrays. You might also be familiar with "adding" to arrays. Well Unity sugarcoated that for you. Arrays are not really re-sizable. When you declare an array in c#,  you have to define it right there. If your looking for something similar to re-sizable arrays, use lists. To use Lists in Unity c#, you must add the line " using System.Collections.Generic; " At the top of your code. Declaring a list of Game Objects would go something like this List<GameObject> myGameObjectList = new List<GameObject>(); Then adding to the list would is as simple as myGameObjectList.Add(gameObjectInstance); Then if you really just want an array you would say something like GameObject[] gameObjectArray = myGameObjectList.ToArray(); The API is not what it always seems. Unity has also sugar coated some of its API, some parts to the point where its practically ...

Simple Reload Script

Sooo I'm working on a simple Top Down Shooter game. And This was the script I came up with for the reloading part of the script. Very simple. I think you can use it with any weapon really. You reload with space. You  need to put your own method of Firing in this script. Comment if you have any questions private var reloading = false; var reloadTime = 2.0; private var st : int; var clipAmmo = 50; var clipSize = 50; var stockAmmo = 100; function Update () { if (Input.GetKeyDown ("space")){ if(clipAmmo<clipSize && reloading == false && stockAmmo !=0){ SaveTime(Time.time); reloading = true; } } if(st < Time.time && reloading == true){ Reload(); } } //Making it show that you are reloading. function OnGUI(){ if(reloading == true){ GUI.Box(Rect(250,200,100,25),"Reloading"); } } function Reload(){ if(clipAmmo < clipSize){ var neededAmmo = clipSize-clipAmmo; if(stockA...

Debug Rays =D

I use them for looking at what enemies are looking or aiming at. Since it's Debug it only shows up in the scene view and not in your actual game play. They  can be very useful sometimes. Here's an example of what they look like. The red lines are the debug rays.

Collision/Trigger

An overview of how to use OnCollision and OnTrigger functions. Which almost all games have. Ha..

Making Classes..

A dip into JavaScript. Before I begin. var is a variable. You need to declare your variables before you start writing code so the code will execute properly. Declaring a function goes like this: function Update(){ //Insert your code here.... }