Readable
Readable
CC#
Created by Readable on 1/26/2025 in #help
CS0120 Error Code help
Thank you, its working
16 replies
CC#
Created by Readable on 1/26/2025 in #help
CS0120 Error Code help
It’s at the shoot function
16 replies
CC#
Created by Readable on 1/26/2025 in #help
CS0120 Error Code help
idk why its so small
16 replies
CC#
Created by Readable on 1/26/2025 in #help
CS0120 Error Code help
No description
16 replies
CC#
Created by Readable on 1/26/2025 in #help
CS0120 Error Code help
// using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
class Gun{
public Rigidbody projectile;
public float speed = 25;
// Update is called once per frame
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
shoot();
}
}
public void shoot()
{
Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
}
}
class Throw : Weapon
{
[SerializeField] private Transform targetCube;
[SerializeField] private float force;
[SerializeField] private float rotationForce;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.E))
{
Vector3 direction = targetCube.position - rb.position;
direction.Normalize();
Vector3 rotationAmount = Vector3.Cross(transform.forward, direction);
rb.angularVelocity = rotationAmount * rotationForce;
rb.velocity = transform.forward * force;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Enemy"))
{
Destroy(gameObject);
}
}
}
}
// using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
class Gun{
public Rigidbody projectile;
public float speed = 25;
// Update is called once per frame
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
shoot();
}
}
public void shoot()
{
Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
}
}
class Throw : Weapon
{
[SerializeField] private Transform targetCube;
[SerializeField] private float force;
[SerializeField] private float rotationForce;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.E))
{
Vector3 direction = targetCube.position - rb.position;
direction.Normalize();
Vector3 rotationAmount = Vector3.Cross(transform.forward, direction);
rb.angularVelocity = rotationAmount * rotationForce;
rb.velocity = transform.forward * force;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Enemy"))
{
Destroy(gameObject);
}
}
}
}
16 replies
CC#
Created by Readable on 1/22/2025 in #help
Help with defintions in my code (CS1061 AND CS0103)
thank you so much
5 replies