c_ccc
c_ccc
CC#
Created by c_ccc on 2/15/2023 in #help
❔ I cant get jumping to work
Ik I am new to scripting but this one is just stupid. For the life of me, the jumping wont seem to work. void Update() { transform.rotation = Quaternion.Euler(0, angle, 0); float horizontalInput = Input.GetAxis("Horizontal"); angle -= horizontalInput * angleSpeed * Time.deltaTime; Vector3 newPosition = Quaternion.Euler(0, angle, 0) * new Vector3(0, 0, radius); transform.position = newPosition; if(Input.GetKeyDown(KeyCode.Space)|| Input.GetKeyDown(KeyCode.W)) { Debug.Log("Jumping!"); rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); } }
4 replies
CC#
Created by c_ccc on 12/15/2022 in #help
❔ FADE CANVAS GROUP (DELTATIME-UI)
smallLogoFade.alpha = 1 - Time.deltaTime * fadeSpeed;
smallLogoFade.alpha = 1 - Time.deltaTime * fadeSpeed;
(smallLogoFade is the canvas group) this is within a function called
private void mainUISpawn()
private void mainUISpawn()
im trying to make the transparency fade over time for some reason the opacity drops to 0.92 something and freezes i figured that it is because it is literally calling the last frame which is pretty consistent but now i have NO clue how to make it fade within this function
6 replies
CC#
Created by c_ccc on 11/3/2022 in #help
Update Text Color OnTriggerEntry
Within ZoneUpdater, I have a public colour variable that can be changed within the editor Based on this, under my other script within void Update(), I have:
zoneDisplayUI.color = gameObject.GetComponent<ZoneUpdater>().textColour;
zoneDisplayUI.text = "ZONE: " + currentZone;
zoneDisplayUI.color = gameObject.GetComponent<ZoneUpdater>().textColour;
zoneDisplayUI.text = "ZONE: " + currentZone;
Why doesnt this work, currently it completely removes my text
12 replies
CC#
Created by c_ccc on 10/23/2022 in #help
Bullet Kills Wrong Enemy
If I shoot and hit an enemy, sometimes it will kill the wrong one. For example, if i hit 'EnemyTest', it might end up killing 'EnemyTest (2)' that is miles away. BulletController Code:
using UnityEngine;

public class BulletController : MonoBehaviour
{
public float shootSpeed;
float freezeTime = .15f;
Rigidbody m_Rigidbody;
float bulletFreeze = 2f;
private GameObject reelBack;
public GunController gunScript;
Enemy1 enemyScript;

// Start is called before the first frame update
void Start()
{
gunScript = GameObject.FindObjectOfType<GunController>();
enemyScript = GameObject.FindObjectOfType<Enemy1>();
reelBack = GameObject.FindGameObjectWithTag("POINT");
m_Rigidbody = GetComponent<Rigidbody>();
gunScript.canFire = false;
}

// Update is called once per frame
void Update()
{
freezeTime -= Time.deltaTime; //new
if (freezeTime <= 0)
{
m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ;
bulletFreeze -= Time.deltaTime;
if (bulletFreeze <= 0)
{
Destroy(gameObject, .2f);
transform.LookAt(reelBack.transform);
m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
transform.position += transform.forward * 100*Time.deltaTime;
gunScript.canFire = true;
}
}
if (freezeTime > 0)
{
transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);

}

//transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);
//Destroy(gameObject, 3);

}
***private void OnTriggerEnter(Collider other)
{
if (other.tag == "Enemy")
{
Debug.Log("HIT");
enemyScript.takeDamage(5);


}***
}
}
using UnityEngine;

public class BulletController : MonoBehaviour
{
public float shootSpeed;
float freezeTime = .15f;
Rigidbody m_Rigidbody;
float bulletFreeze = 2f;
private GameObject reelBack;
public GunController gunScript;
Enemy1 enemyScript;

// Start is called before the first frame update
void Start()
{
gunScript = GameObject.FindObjectOfType<GunController>();
enemyScript = GameObject.FindObjectOfType<Enemy1>();
reelBack = GameObject.FindGameObjectWithTag("POINT");
m_Rigidbody = GetComponent<Rigidbody>();
gunScript.canFire = false;
}

// Update is called once per frame
void Update()
{
freezeTime -= Time.deltaTime; //new
if (freezeTime <= 0)
{
m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ;
bulletFreeze -= Time.deltaTime;
if (bulletFreeze <= 0)
{
Destroy(gameObject, .2f);
transform.LookAt(reelBack.transform);
m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
transform.position += transform.forward * 100*Time.deltaTime;
gunScript.canFire = true;
}
}
if (freezeTime > 0)
{
transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);

}

//transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);
//Destroy(gameObject, 3);

}
***private void OnTriggerEnter(Collider other)
{
if (other.tag == "Enemy")
{
Debug.Log("HIT");
enemyScript.takeDamage(5);


}***
}
}
9 replies
CC#
Created by c_ccc on 10/20/2022 in #help
OnTriggerEnter - When player is in zone for 3 seconds, take damage Help
Sorry, I technically posted this a minute ago but due to a radical change in my script, I decided to entirely repost it: I tested the player damage in the ontriggerenter and it works. The ontriggerexit also works. why is the countdown not working?
public class DeathRegion : MonoBehaviour
{
public float countDown = 3f;
float zoneTime;
public GameObject player;
public ControllerTest2 PLcontroller;

void Start()
{
zoneTime = countDown;
//PLcontroller = GameObject.FindObjectOfType<ControllerTest2>();
}

public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
zoneTime -= Time.deltaTime;
Debug.Log("COUNTDOWN START");
}
}

void Update()
{
if (zoneTime <= 0f)
{
PLcontroller.takeDamage(100);
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
zoneTime = countDown;
Debug.Log("Survived");
}

}
}
public class DeathRegion : MonoBehaviour
{
public float countDown = 3f;
float zoneTime;
public GameObject player;
public ControllerTest2 PLcontroller;

void Start()
{
zoneTime = countDown;
//PLcontroller = GameObject.FindObjectOfType<ControllerTest2>();
}

public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
zoneTime -= Time.deltaTime;
Debug.Log("COUNTDOWN START");
}
}

void Update()
{
if (zoneTime <= 0f)
{
PLcontroller.takeDamage(100);
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
zoneTime = countDown;
Debug.Log("Survived");
}

}
}
13 replies
CC#
Created by c_ccc on 10/18/2022 in #help
Camera Isnt Zooming Back Out
So, when the bullet is spawned, the camera zooms in to 55. Why when the FOV is = 55 doenst it zoom back out?
int zoom = 55;
int normal = 60;
float smooth = 12f;
float delay = .5f;
public GunController bulletCheck;
public Camera mainCam;

void Start()
{

}

// Update is called once per frame
void Update()
{
if (bulletCheck.shotSpawned == true)
{
mainCam.fieldOfView = Mathf.Lerp(GetComponent<Camera>().fieldOfView, zoom, Time.deltaTime * smooth);

}
if (mainCam.fieldOfView <= zoom)
{
// mainCam.fieldOfView = normal;
mainCam.fieldOfView = Mathf.Lerp(GetComponent<Camera>().fieldOfView, normal, Time.deltaTime * smooth);
}
}
int zoom = 55;
int normal = 60;
float smooth = 12f;
float delay = .5f;
public GunController bulletCheck;
public Camera mainCam;

void Start()
{

}

// Update is called once per frame
void Update()
{
if (bulletCheck.shotSpawned == true)
{
mainCam.fieldOfView = Mathf.Lerp(GetComponent<Camera>().fieldOfView, zoom, Time.deltaTime * smooth);

}
if (mainCam.fieldOfView <= zoom)
{
// mainCam.fieldOfView = normal;
mainCam.fieldOfView = Mathf.Lerp(GetComponent<Camera>().fieldOfView, normal, Time.deltaTime * smooth);
}
}
5 replies
CC#
Created by c_ccc on 10/13/2022 in #help
Update Variable Between Scripts
Hey there, this isnt my first time updating between scripts so I dont entirely know the issue. I have two scripts, 'GunController' (with the variable: 'public bool canFire;') in which I am trying to update in the script 'BulletController' in theory i have the canfire updated in the start() of bulletcontroller for when the prefab spawns to make the bool false and then when the object gets destroyed, it is then set to true i will simplify the code to the main parts to make it obvious BULLETCONTROLLER:
GunController gunScript;
// Start is called before the first frame update
void Start()
{
reelBack = GameObject.FindGameObjectWithTag("POINT");
m_Rigidbody = GetComponent<Rigidbody>();
gunScript.canFire = false;
}

// Update is called once per frame
void Update()
{
freezeTime -= Time.deltaTime; //new
if (freezeTime <= 0)
{
m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ;
bulletFreeze -= Time.deltaTime;
if (bulletFreeze <= 0)
{
Destroy(gameObject, .2f);
transform.LookAt(reelBack.transform);
transform.position += transform.forward * 100*Time.deltaTime;
gunScript.canFire = true;
}
}
if (freezeTime > 0)
{
transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);

}
GunController gunScript;
// Start is called before the first frame update
void Start()
{
reelBack = GameObject.FindGameObjectWithTag("POINT");
m_Rigidbody = GetComponent<Rigidbody>();
gunScript.canFire = false;
}

// Update is called once per frame
void Update()
{
freezeTime -= Time.deltaTime; //new
if (freezeTime <= 0)
{
m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ;
bulletFreeze -= Time.deltaTime;
if (bulletFreeze <= 0)
{
Destroy(gameObject, .2f);
transform.LookAt(reelBack.transform);
transform.position += transform.forward * 100*Time.deltaTime;
gunScript.canFire = true;
}
}
if (freezeTime > 0)
{
transform.Translate(Vector3.up * shootSpeed * Time.deltaTime);

}
44 replies
CC#
Created by c_ccc on 10/13/2022 in #help
Line Renderer Help
I am trying to get this code to work There is no bullet in the map at the start of the game when the player shoots, a bullet prefab is spawned i want a line to render from pos1 ( a set point ) to the spawned bullet and repeat everytime
public class LinePositions : MonoBehaviour
{
public LineRenderer theline;
public Transform pos11;
public GameObject BULLET;

// Start is called before the first frame update
void Start()
{
BULLET = GameObject.FindGameObjectWithTag("Bullet");
theline.enabled = false;
theline.positionCount = 2;
}

// Update is called once per frame
void Update()
{
if(BULLET != null)
{
theline.SetPosition(0, pos11.position);
theline.SetPosition(1, BULLET.transform.position);
theline.enabled = true;
}

}
}
public class LinePositions : MonoBehaviour
{
public LineRenderer theline;
public Transform pos11;
public GameObject BULLET;

// Start is called before the first frame update
void Start()
{
BULLET = GameObject.FindGameObjectWithTag("Bullet");
theline.enabled = false;
theline.positionCount = 2;
}

// Update is called once per frame
void Update()
{
if(BULLET != null)
{
theline.SetPosition(0, pos11.position);
theline.SetPosition(1, BULLET.transform.position);
theline.enabled = true;
}

}
}
12 replies