Translate









How do I use Translate
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PaddleScript.cs Copy
14     void Update()
15     {
16         float input;
17
18         if (Input.touchCount > 0)//touch input
19         {
20             input = Input.touches[0].position.x >= Screen.width / 2 ? 1f : -1f;
21         }
22         else//keyboard input
23         {
24             input = Input.GetAxis("Horizontal");
25         }
26
27         transform.Translate(new Vector2(input * speed * Time.deltaTime, 0));
28         float currentX = Mathf.Clamp(transform.position.x, LeftBlockTransform.position.x + 1, RightBLockTransform.position.x - 1);
29         transform.position = new Vector3(currentX, transform.position.y, transform.position.z);
30     }

Translate 161 lượt xem

Gõ tìm kiếm nhanh...