Проигрывание Анимации через кнопку button
Добавлено: 07 сен 2018, 12:23
Нужна помошь.Как сделать так чтобы через кнопку button на сцене игры проигрывалась Анимация объекта.Новичок в этой области не судить строго.Вот скрипт написанный мною.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript1 : MonoBehaviour {
float t;
public float Speed;
public float Angle;
public float Gravity = 9.8f;
int Push;
int Deploy;
public Animator Launch;
// Use this for initialization
void Start ()
{
Angle = Vector3.Angle(transform.forward, Vector3.forward);
Angle = Angle * Mathf.Deg2Rad;
Launch = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetButton("Push"))
{
t = Time.time / 6;
float vz = Speed * Mathf.Cos(Angle) * Time.deltaTime;
float vy = Speed * Mathf.Sin(Angle) * Time.deltaTime - Gravity * (t * t) / 2 * Time.deltaTime;
transform.position += new Vector3(0, vy, vz);
}
if (Input.GetButtonDown("Deploy")) Launch.GetBool("Launch", false);
else Launch.GetBool("Launch", true);
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript1 : MonoBehaviour {
float t;
public float Speed;
public float Angle;
public float Gravity = 9.8f;
int Push;
int Deploy;
public Animator Launch;
// Use this for initialization
void Start ()
{
Angle = Vector3.Angle(transform.forward, Vector3.forward);
Angle = Angle * Mathf.Deg2Rad;
Launch = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetButton("Push"))
{
t = Time.time / 6;
float vz = Speed * Mathf.Cos(Angle) * Time.deltaTime;
float vy = Speed * Mathf.Sin(Angle) * Time.deltaTime - Gravity * (t * t) / 2 * Time.deltaTime;
transform.position += new Vector3(0, vy, vz);
}
if (Input.GetButtonDown("Deploy")) Launch.GetBool("Launch", false);
else Launch.GetBool("Launch", true);
}
}