- Home /
Question by
FusionSausage · Sep 15, 2013 at 08:41 PM ·
javascriptobjectssurfaceplace
Multiple objects to one excecute method
Hey guys, I've got a problem. I have a script which is gonna place some stuff on the surface which is working. The problem is that I don't know how i can switch between the objects which are gonna be placed by pressing a number, say 1 for cube or 2 for cylinder.
Here is the code:
import System.Collections.Generic;
var TowerPrefab : Transform;
var Object1 : Transform;
var Object2 : Transform;
var prefabTransforms : List.<Transform>;
function Update () {
if (Input.GetKeyDown ("1")){
prefabTransforms.Add(Object1);
Debug.Log("Pressed 1, outputs Cube");}
if (Input.GetKeyDown ("2")){
PickedObject.Add(Object2);
Debug.Log("Pressed 2, outputs Cylinder");}
var Objects = prefabTransforms;
}
function OnMouseUp ()
{
var Eye : GameObject = GameObject.Find("Eye");
var thisItem = List[i];
var ray = Eye.camera.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 2000))
{
Instantiate(Objects, hit.point, Quaternion.identity);
Debug.Log("Prefab cloned!");
}
}
I understood I'd use list although I don't have a clue how to go from here.. Thanks in advance :)
Comment
Your answer
Follow this Question
Related Questions
Adding Object Avoidance to my Enemy AI Script 1 Answer
Hiding and showing multiple objects 1 Answer
Play sound when clicking object 1 Answer
Trying to move an object between two points 2 Answers
PENDULUM EFFECT 0 Answers