So i’ve tried myself for a couple of hours, but i haven’t been able to make it work yet.
I wanted to translate this jave code into C#
#pragma strict
var projectile : Rigidbody;
var speed = 100;
function Update () {
if(Input.GetButtonDown(“Fire1”)){
var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, speed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
}
}
What i figured out myself so far is:
using UnityEngine;
using System.Collections;
public class Weapon : MonoBehaviour {
public Rigidbody projectile;
public float speed = 100.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown(“Fire1”))
Rigidbody.Instantiate(projectile, transform.position, transform.rotation);
projectile.velocity = Vector3(0, 0, speed);
Physics.IgnoreCollision(projectile.collider, transform.root.collider);
}
}
My issue seems to be the line that says
“projectile.velocity = Vector3(0, 0, speed);”
So if anyone could help me with this i’d appriciate it very much