Hello, So I’m a beginner and will just get straight to the point, I’m trying to make a shot go horizontally, but I don’t get what my error is please help here is the code below and the error message i get.
Error Message(1) : error CS0266: Cannot implicitly convert type UnityEngine.Object' to
UnityEngine.GameObject’. An explicit conversion exists (are you missing a cast?)
Error Message(2) : error CS1061: Type UnityEngine.Component' does not contain a definition for
velocity’ and no extension method velocity' of type
UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
//A variable(box in inspector where you can adjust the speed of the moving character(Player))
public float speed = 5.0f;
public float padding = 1;
public GameObject bulletShot;
private float xmax = 78;
private float xmin = -79;
public float projectileSpeed;
void Start() {
Camera camera = Camera.main;
float distance = transform.position.z - camera.transform.position.z;
xmin = camera.ViewportToWorldPoint(new Vector3(0,0,distance)).x + padding;
xmax = camera.ViewportToWorldPoint(new Vector3(1,1,distance)).x + padding;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) {
GameObject beam = Instantiate(bulletShot, transform.position, Quaternion.identity);
beam.rigidbody2D.velocity = new Vector3 (projectileSpeed,0,0);
}
//Allowing the player to move in the X-axis
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
transform.position = new Vector3 (
Mathf.Clamp(transform.position.x - speed * Time.deltaTime, xmin,xmax),
transform.position.y,
transform.position.z
);
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
// Rotate the object around its local X axis at 1 degree per second
transform.position = new Vector3 (
Mathf.Clamp(transform.position.x + speed* Time.deltaTime, xmin, xmax),
transform.position.y,
transform.position.z
);
}
}
}