I am working on my very first IOS game, I don't have an apple developer license yet so i am testing the game using mouse click. In this prototype stage want to be able essentially "draw" red cylinders (lava) on a plane a slight angle from the camera. I will be able to change this code to Mobil format fairly easily, but there is a bit of a problem
the code only works when the game is in orthographic mode.
var particlething : GameObject;
var lasthit : RaycastHit;
var hit : RaycastHit;
var cylinderPrefab : GameObject;
function CreateCylinderBetweenPoints(start : Vector3, end : Vector3, width : float)
{
var offset = end - start;
var scale = new Vector3(width, offset.magnitude / 2.0, width);
var position = start + (offset / 2.0);
var cylinder = Instantiate(cylinderPrefab, position, Quaternion.identity);
cylinder.transform.up = offset;
cylinder.transform.localScale = scale;
}
function Update (){
var p : Vector3 = camera.ScreenToWorldPoint (Vector3(Input.mousePosition.x,Input.mousePosition.y,0.1));
if(Input.GetMouseButton(0) == true){
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (p, fwd, hit)) {
if(lasthit != null){
CreateCylinderBetweenPoints(hit.point, lasthit.point, 1);
}
lasthit = hit;
}
}
}
the perspective camera throws the script off. Although an orthographic camera is okay, I would prefer a perspective one (Only If it isn't going to be to hard to make it into perspective. because this is my first game, i can live without some visual effects.)
is there any easy way to do what i am trying to do?
↧