This uses mouse or finger to generate an force called pPush, which is then applied to a ball.
nFrame is Time.deltaTime
all other vars with a "p" in front need declared at the top of your script.
void FingerThing(float nFrame){
pGo=false;
if(Input.GetKey(KeyCode.Mouse0)){
Vector2 vFinger = Input.mousePosition;
Vector3 vPlace = this.camera.ScreenToWorldPoint (new Vector3 (vFinger.x,vFinger.y,100));
if(!pOldPress){
pTime=nFrame;
pStartPos=vPlace;
}else{
pTime+=nFrame;
}
pFirePos=vPlace;
pOldPress=true;
}else{
if(pOldPress){
pPush=(pFirePos-pStartPos)/pTime;
pGo=true;
}
pOldPress=false;
}
}
↧