// Changed: 2014 10 26 10:29 PM : 5665tm
using UnityEngine;
public static class PositionExtension
{
// Установка глобальных значений
public static void X (this Transform tr, float newValue)
{
tr.position = new Vector3(newValue, tr.position.y, tr.position.z);
}
public static void Y(this Transform tr, float newValue)
{
tr.position = new Vector3(tr.position.x, newValue, tr.position.z);
}
public static void Z(this Transform tr, float newValue)
{
tr.position = new Vector3(tr.position.x, tr.position.y, newValue);
}
public static void X (this GameObject go, float newValue)
{
go.transform.position = new Vector3(newValue, go.transform.position.y, go.transform.position.z);
}
public static void Y(this GameObject go, float newValue)
{
go.transform.position = new Vector3(go.transform.position.x, newValue, go.transform.position.z);
}
public static void Z(this GameObject go, float newValue)
{
go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, newValue);
}
// Получение глобальных значений
public static float X (this Transform tr)
{
return tr.position.x;
}
public static float Y(this Transform tr)
{
return tr.position.y;
}
public static float Z(this Transform tr)
{
return tr.position.z;
}
public static float X (this GameObject go)
{
return go.transform.position.x;
}
public static float Y(this GameObject go)
{
return go.transform.position.y;
}
public static float Z(this GameObject go)
{
return go.transform.position.z;
}
// Установка локальных значений
public static void LocX(this Transform tr, float newValue)
{
tr.localPosition = new Vector3(newValue, tr.localPosition.y, tr.localPosition.z);
}
public static void LocY(this Transform tr, float newValue)
{
tr.localPosition = new Vector3(tr.localPosition.x, newValue, tr.localPosition.z);
}
public static void LocZ(this Transform tr, float newValue)
{
tr.localPosition = new Vector3(tr.localPosition.x, tr.localPosition.y, newValue);
}
public static void LocX(this GameObject go, float newValue)
{
go.transform.localPosition = new Vector3(newValue, go.transform.localPosition.y, go.transform.localPosition.z);
}
public static void LocY(this GameObject go, float newValue)
{
go.transform.localPosition = new Vector3(go.transform.localPosition.x, newValue, go.transform.localPosition.z);
}
public static void LocZ(this GameObject go, float newValue)
{
go.transform.localPosition = new Vector3(go.transform.localPosition.x, go.transform.localPosition.y, newValue);
}
// Получение локальных значений
public static float LocX(this Transform tr)
{
return tr.localPosition.x;
}
public static float LocY(this Transform tr)
{
return tr.localPosition.y;
}
public static float LocZ(this Transform tr)
{
return tr.localPosition.z;
}
public static float LocX(this GameObject go)
{
return go.transform.localPosition.x;
}
public static float LocY(this GameObject go)
{
return go.transform.localPosition.y;
}
public static float LocZ(this GameObject go)
{
return go.transform.localPosition.z;
}
}
|
frequ3ncy1 0 / 0 / 0 Регистрация: 28.09.2019 Сообщений: 30 |
||||
|
1 |
||||
Движение камеры только по одной координате27.12.2019, 09:44. Показов 1010. Ответов 1 Метки нет (Все метки)
Как вы поняли камера следует за игроком в какую сторону бы он не пошёл, но суть в том что игра типо раннера и нужно что бы она двигалась только по координате «Z»
__________________
0 |
|
Ttemik vk.com/pppoe252110 62 / 43 / 21 Регистрация: 31.05.2019 Сообщений: 251 |
||||
|
27.12.2019, 10:28 |
2 |
|||
|
Просто сделай
0 |
|
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
27.12.2019, 10:28 |
|
2 |
Suggest a change
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close
Your name
Your email
Suggestion*
Cancel
Switch to Manual
Description
The world space position of the Transform.
The position property of a GameObject’s Transform, which is accessible in the Unity Editor and through scripts. Alter this value to move a GameObject. Get this value to locate the GameObject in 3D world space.
using UnityEngine;public class ExampleClass : MonoBehaviour { //movement speed in units per second private float movementSpeed = 5f;
void Update() { //get the Input from Horizontal axis float horizontalInput = Input.GetAxis("Horizontal"); //get the Input from Vertical axis float verticalInput = Input.GetAxis("Vertical");
//update the position transform.position = transform.position + new Vector3(horizontalInput * movementSpeed * Time.deltaTime, verticalInput * movementSpeed * Time.deltaTime, 0);
//output to log the position change Debug.Log(transform.position); } }
The example gets the Input from Horizontal and Vertical axes, and moves the GameObject up/down or left/right by changing its position.
@horosami
ux/ui designer
хочу плавно сместить объект по одной координате на небольшое расстояние.
пробовала через трансформ, но не понимаю как приделать Time.deltaTime, чтобы было видно движени
-
Вопрос заданболее трёх лет назад
-
4827 просмотров
Вариантов несколько, например можете использовать Vector3.Lerp:
using UnityEngine;
public class Example : MonoBehaviour
{
public Vector3 fromPosition = Vector3.zero;
public Vector3 toPosition = Vector3.one;
public float speed = 1;
private float progress;
private void Update()
{
progress += Time.deltaTime*speed;
transform.position = Vector3.Lerp(fromPosition, toPosition, progress);
}
}
Пригласить эксперта
void Update(){
transform.Translate(Vector3.Forward*Speed*Time.deltaTime);}
-
Показать ещё
Загружается…
10 февр. 2023, в 21:36
3000 руб./за проект
10 февр. 2023, в 21:23
2000 руб./за проект
10 февр. 2023, в 20:59
3000 руб./за проект


