https://i.sstatic.net/vmx8f.jpg on on the on the on the on on the on on the on on the on on the on on the on on the on on the on on the on the on on the on on the on on the on on the on in the on on the nember sladd Электрические кабели и на рельсах. Как я могу создать тот же результат? в C#. Смотрите это видео: (от 1,20 мин до 1,25). Я создал этот код: -ontrigger- (применить к электрическим кабелям) < /p>
Код: Выделить всё
using UnityEngine;
using System.Collections;
public class OnTriggerEnterScroll : MonoBehaviour
{
/*ISTRUZIONI : Inserire questo Script all'interno dell'Elemento che entra in contatto con il Trigger */
public Transform target; // Player
AutoMove AutoMoveScript; // richiamo variabili Script AutoMove
// Use this for initialization
void Start () {
AutoMoveScript = target.GetComponent(); // Richiano componente AutoMove
}
// Update is called once per frame
void Update () {
Vector3 targetDir = target.position - transform.position;
Debug.Log(targetDir);
}
void OnTriggerEnter(Collider other) { // Quando il player entra nel Trigger
if(other.collider.name == "MainCharacter"){
AutoMoveScript.MoveSpeed = 8; // Cambio variabile di Velocita'
AutoMoveScript.activeAutoMoveW = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
}
}
void OnTriggerStay(Collider other) { // Quando il player e' nel Trigger
if(other.collider.name == "MainCharacter"){
if(Input.GetKey(KeyCode.W)){
AutoMoveScript.activeAutoMoveW = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
}
if(Input.GetKey(KeyCode.S)){
AutoMoveScript.activeAutoMoveS = true; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveW = false; // Cambio variabile di scorrimento
}
}
}
void OnTriggerExit(Collider other) { // Quando il player esce nel Trigger
if(other.collider.name == "MainCharacter"){
AutoMoveScript.MoveSpeed = 8; // Cambio variabile di Velocita'
AutoMoveScript.activeAutoMoveS = false; // Cambio variabile di scorrimento
AutoMoveScript.activeAutoMoveW = false; // Cambio variabile di scorrimento
}
}
}
< /code>
-automove- (применить на главном персонаже) < /p>
с использованием unityEngine; Использование System.collections; Public Class Automove:
Monobehaviour {< /p>
/*ISTRUZIONI : Inserire questo Script all'interno del Player */
public bool activeAutoMoveW = false; //variabile controllo Forward
public bool activeAutoMoveS = false; //variabile controllo Back
public int MoveSpeed = 8; //variabile velocità di scorrimento
public bool activeSelect = false; //variabile controllo Select
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(activeAutoMoveW == true)
{
transform.Translate(Vector3.forward * MoveSpeed * Time.fixedDeltaTime, Space.World); // Scorrimento in avari
}
if(activeAutoMoveS == true)
{
transform.Translate(Vector3.back * MoveSpeed * Time.fixedDeltaTime, Space.World); // Scorrimento in dietro
}
if(Input.GetKeyDown(KeyCode.Q) && activeSelect == false)
{
MoveSpeed = 1; // Cambio variabile di scorrimento
activeSelect = true; // Cambio variabile Slect
}else if(Input.GetKeyDown(KeyCode.Q) && activeSelect == true)
{
MoveSpeed = 8; // Cambio variabile di scorrimento
activeSelect = false; // Cambio variabile Slect
}
} }
Подробнее здесь: https://stackoverflow.com/questions/242 ... -and-rails