- Код: Выделить всё
function Update () {
...
obj.transform.Translate(Vector3(0,0,speed*Time.deltaTime), сam.transform);
...
}
Хотя, может это решение и хорошее.
function Update () {
...
obj.transform.Translate(Vector3(0,0,speed*Time.deltaTime), сam.transform);
...
}
using UnityEngine;
using System.Collections;
public class mCoconutThrow_sha : MonoBehaviour
{
public Rigidbody myShellPrefab;
public int ShellForce = 20;
public AudioClip ShellClip;
public Vector3 ShellRotate;
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Fire2"))
{
Rigidbody Coconut = (Rigidbody)Instantiate(myShellPrefab, transform.position, transform.rotation);
Coconut.transform.Rotate(ShellRotate);
Coconut.velocity = transform.TransformDirection(0, 0, ShellForce);
Physics.IgnoreCollision(Coconut.collider, transform.root.collider);
audio.PlayOneShot(ShellClip);
}
}
}
void OnCollisionEnter(Collision Info) {
if (transform.gameObject.name!="bullet")
Destroy(transform.gameObject);
}
using UnityEngine;
using System.Collections;
public class shoot : MonoBehaviour {
Transform Tar_pos;
Transform Tar_rot;
GameObject Obj;
GameObject Bullet;
int speed;
void OnCollisionEnter(Collision Info) {
if (transform.gameObject.name!="bullet")
Destroy(transform.gameObject);
}
// Use this for initialization
void Start () {
speed=1000;
Tar_pos = GameObject.Find("wpn_launcher").transform;
Tar_rot = GameObject.Find("Main Camera").transform;
Obj = GameObject.Find("bullet");
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButtonDown ("Fire1")) {
if (transform.gameObject.name=="bullet") {
GameObject Bullet = (GameObject) Instantiate(Obj, Tar_pos.position, Tar_rot.rotation);
Bullet.rigidbody.velocity = Tar_rot.TransformDirection(0, 0, speed);
}
}
}
}
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 9