Quantcast
Channel: Questions in topic: "hold"
Viewing all articles
Browse latest Browse all 154

Hold touch button Unity Javascript

$
0
0
I have script for crouching when i press and hold S its crouching when i release the button the player gets in his normal size. Now i want to do the same thing with touch button but i cant figure how to do that, can some1 help? static var vScale = 1.0; private var tr: Transform; private var dist: float; // distance to ground function Start(){ tr = transform; var ch:CharacterController = GetComponent(CharacterController); dist = ch.height/2; // calculate distance to ground } function Update() { vScale = 1.0;s if (Input.GetKey("s")){ // press s to crouch vScale = 0.5; } var ultScale = tr.localScale.y; // crouch/stand up smoothly tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime); tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position } function OnGUI () { }

Viewing all articles
Browse latest Browse all 154

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>