Please don’t kill me, i’m newbie…
So, i’m lost what should be with what, and this way i made 3 errors (if i know my actual skills, they are stupid). Don’t mind if you don’t know few words, i’m just mixing english and my own language (polish)
- at Karabin 108,21: error CS1061: ‘BasicEnemy’ does not contain a definition for ‘takeDamage’ and no accessible extension method ‘takeDamage’ accepting a first argument of type ‘BasicEnemy’ could be found (are you missing a using directive or an assembly reference?)
2 and 3 at BasicEnemy 54,3 and 22: error CS0103: The name ‘basicEnemy’ does not exist in the current context
and codes:
- BasicEnemy
using System.Diagnostics;
using System.Security.Cryptography;
using UnityEngine;
public class BasicEnemy : MonoBehaviour {
[HideInInspector]
public float speed;
public float startSpeed = 10f;
public int health = 150;
public int moneyGain = 30;
public GameObject deathEffect;
private Transform target;
private int wavepointIndex = 0;
void Start()
{
speed = startSpeed;
target = Waypoints.points[0];
}
public void TakeDamage (int amount)
{
health -= amount;
if (health <= 0)
{
Die();
}
}
void Die ()
{
GameObject effect = (GameObject)Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(effect, 2f);
PlayerStats.Money += moneyGain;
Destroy(gameObject);
}
void Update()
{
Vector3 dir = target.position - transform.position;
transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
if (Vector3.Distance(transform.position, target.position) <= 0.4f)
{
GetNextWaypoint();
}
basicEnemy.speed = basicEnemy.startSpeed;
}
public void Slow(float pct)
{
speed = startSpeed * (1f - pct);
speed = startSpeed;
}
void GetNextWaypoint()
{
if (wavepointIndex >= Waypoints.points.Length - 1)
{
EndPath();
return;
}
wavepointIndex++;
target = Waypoints.points[wavepointIndex];
}
void EndPath ()
{
PlayerStats.Lives--;
Destroy(gameObject);
}
}
and Karabin
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Security.Cryptography;
using UnityEngine;
public class Karabin : MonoBehaviour
{
private Transform target;
public float range = 20f;
public float fireRate = 0.5f;
private float fireCountdown = 0f;
[Header("Rotacja, cele")]
public Transform partToRotate;
public float turnSpeed = 1f;
public string enemyTag = "Enemy";
public GameObject bulletPrefab;
public Transform firePoint;
[Header("Slow")]
public bool useSlow = false;
public float slowStrenght = .3f;
[Header("Poison")]
public bool usePoison = false;
public int poisonValue = 1;
private BasicEnemy targetEnemy;
void Start()
{
InvokeRepeating("UpdateTarget", 0f, 0.3f);
}
void UpdateTarget ()
{
GameObject [] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
float shortestDistance = Mathf.Infinity;
GameObject nearestEnemy = null;
foreach (GameObject enemy in enemies)
{
float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
if (distanceToEnemy < shortestDistance)
{
shortestDistance = distanceToEnemy;
nearestEnemy = enemy;
}
}
if (nearestEnemy != null && shortestDistance <= range)
{
target = nearestEnemy.transform;
targetEnemy = nearestEnemy.GetComponent<BasicEnemy>();
} else
{
target = null;
}
}
void Update()
{
if (target == null)
return;
LockOnTarget();
if (usePoison)
{
Poison();
} else
{
if (fireCountdown <= 0f)
{
Shoot();
fireCountdown = 1f / fireRate;
}
fireCountdown -= Time.deltaTime;
if (useSlow)
{
Slow();
}
}
}
void LockOnTarget ()
{
Vector3 dir = target.position - transform.position;
Quaternion lookRotation = Quaternion.LookRotation(dir);
Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime * turnSpeed).eulerAngles;
partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
}
void Poison ()
{
targetEnemy.takeDamage(poisonValue * Time.deltaTime);
}
void Slow ()
{
targetEnemy.Slow(slowStrenght);
}
void Shoot ()
{
GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Pocisk bullet = bulletGO.GetComponent<Pocisk>();
if (bullet != null)
bullet.Seek(target);
}
void OnDrawGizmosSelected ()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, range);
}
}