两个球之间发生碰撞并向后移动. [英] collision between two ball and move reverse.

查看:83
本文介绍了两个球之间发生碰撞并向后移动.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在碰撞对象向后移动,但是我无法通过代码完成操作.使用UnityEngine;
可以帮助任何人

i m trying after collision object move reverse but i m unable to do through code. can any one help

推荐答案

使用System.Collections;

公共类MovCube:MonoBehaviour {
公共转换目标;
Vector3开始;
Vector3 end;
public bool show = false;
公共浮子重力= 2.8f;
公共浮子速度= -10.0f;
公众持股y = 20.0f;
公共浮动时间= 0;
//public float m = Mathf.Tan(30.0f);
//将其用于初始化
void Start(){

}

//每帧调用一次更新
void Update(){
时间+ = Time.deltaTime * 0.05f;
y-=速度* Time.deltaTime;
if(!show)
{



transform.position =新Vector3(0,y,0);
}
}
void OnCollisionEnter(碰撞碰撞)
{

if(collision.gameObject.tag ==飞机")
{
show = true ;;

transform.position = new Vector3(0,-y,0);


}
其他{
show = false;
}
}
}
using UnityEngine;
using System.Collections;

public class MovCube : MonoBehaviour {
public Transform target;
Vector3 start;
Vector3 end;
public bool show = false;
public float gravity = 2.8f;
public float velocity =-10.0f;
public float y = 20.0f;
public float time = 0;
//public float m = Mathf.Tan(30.0f);
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
time += Time.deltaTime*0.05f;
y -= velocity * Time.deltaTime;
if(!show)
{



transform.position =new Vector3(0,y,0);
}
}
void OnCollisionEnter(Collision collision)
{

if(collision.gameObject.tag == "Plane")
{
show = true;;

transform.position = new Vector3(0,-y,0);


}
else{
show = false;
}
}
}


这篇关于两个球之间发生碰撞并向后移动.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆