Dear community, I am currently working on making my graduation project, I'm a designer in my last year, and as final project I wanted to make something to be truly proud off. So I wanted to design, write build and program the whole thing myself. With the help of friends I managed to get pretty far with programming in C#, I have a couple of things working in my level and it's getting along nicely. But there are things I keep walking in to, things that I can't solve or cannot find a case applicable to my problem on the forums. Then when I try to understand the information that is given in the problem I find myself getting lost in terms I do not understand or do not know how to apply them and cannot solve the problem on my own. I will not ask you to write my code for me, it's something I want to do. The code I am writing is not complicated, and I am coding some simple things, to portray the story of my game. I just need some help with understanding how some of my code works. I want to be able to solve these problems myself and not having to ask help with terribly simple things. The project is due in 1.5 month, halfway October, so I am not in a huge rush, but my question now is if some of you would be kind enough to help me?
Here is a small example of what I mean, this piece of code is almost done. Code (CSharp): using UnityEngine; using System.Collections; public class TrapTrigger : MonoBehaviour { public GameObject playa; // Use this for initialization void Start () { } void OnCollisionEnter(Collision col) { if (otherObj == "playa") { Destroy(Plane,.5f); } } void OnCollisionExit(Collision col){ if (Time.timeScale == 1.0F) { Time.timeScale = 0.7F; } else { Time.timeScale = 1.0F; Time.fixedDeltaTime = 0.02F * Time.timeScale; } } // Update is called once per frame void Update () { } } I just don't know why otherObj is depicted red in my code, I know it's something that is not present in my code, just don't know what to put in that space, the same goes for col behind Collision. those are the small things I keep hanging up on, maybe a bit strange, but I really need to know.
well I would say that in OnCollisionEnter if you want to check if the colliding object is actually player, you need to check the collision object : col.gameObject and compare it to the playa game object - playa (without "" . With "" you would be checking some string. e.g. tag - col.gameObjet.tag == "player"). In OnCollisionExit you should check which object actually left collider. So something like this : if(col.gameObject == playa) .. I hope it helps...
ok, here is another one I need a little help with. I have this code which handles my events one by one to play in sequence after each other, at the moment I have two different classes that are added to the sequence at the moment but once again I do not know exactly what comes after a certain call within the code, hope some of you can help me with that. Code (CSharp): using UnityEngine; using System.Collections; public class Fall_Event_Trigger : MonoBehaviour { public Sequence_State m_sequenceState; //holder voor de huidige state public float[] m_sequenceDuration; //array van de durations, deze moet even lang zijn als het aantal states in squence_state (5 dus) public float current_duration; //houdt bij hoe lang de huidige state aan de gang is public TrapTrigger tt; public ClimbCollision cc; public enum Sequence_State // enum type om deze specifieke sequence mee op te delen { Fall, Climb, End, } // Use this for initialization void Start () { } // Update is called once per frame void Update () {// maak apparte class, maak een naam aan onder public class, dan naam toevoegen aan sequence state switch (m_sequenceState) { //anything that has to happen every frame during a specific state, call it here. case Sequence_State.Fall: // Do nothing break; case Sequence_State.Climb: CountSequenceTime(); break; case Sequence_State.End: // do nothing, or destroy self or something break; } } void CountSequenceTime() { current_duration += Time.deltaTime; if(current_duration > m_sequenceDuration[(int)m_sequenceState]) { current_duration = 0; m_sequenceState++; switch (m_sequenceState) { /// if there is anything that has to happen (or be called) ONCE at the start of the sequence, do it here case Sequence_State.Fall: tt.(); break; case Sequence_State.Climb: cc.(); break; case Sequence_State.End: break; } } } /*public void StartWithBirds() // public functie die door bijv een andere trigger script kan worden gecalled. { m_sequenceState = Sequence_State.Birds; } public void OnTriggerEnter(Collider col) { if (m_sequenceState == Sequence_State.Waiting) { StartWithBirds(); } } */ } I am talking about the two classes under void countsequence, called tt and cc, have no idea what I have to add behind that period. Can anyone help?
How are you writing code that you don't understand? Are you copying this from somewhere? Are you using an external library? Does that library come with documentation? TrapTrigger ad ClimbCollision aren't part of the Unity API and you haven't really been clear about what they do and how that relates to what your'e trying to do (whatever it is you're trying to do) so it's nearly impossible to provide any guidance.
I have some help from friends, but I do understand the code I am writing. I know what I have to do with the code, the problem is the small fixes that i have to preform to make the code work, those are the ones that sometimes have trouble with. for instance with this example I know I have to add a few lines of code to make this script recognize the other two and make them run together with this scripts. That I have to add a public void with a name I can then link to this class and put behind the tt. but the thing simply is that I have never had unity programming in our school, there some things I know and some things I don't and sadly some of the simpler ones I do not. That is basically where my problem lies.
Hello fourm, I'm back with another little problem I have stumbled on during the creation of my Graduation project. At the moment I am trying to create swimmable water in my game, and I am almost there, except for one little thing. I have followed a tutorial on youtube telling me how to make the swimmable water work, this tutorial uses the charecter controller and character motor of the unity engine. I have written my own character controller for my game and here is also where the probelem arises. I am missing one value I need to pass to make the code work, but I can't figure out which it is. I'll post both my character controller and my swimmer code, and hopefully someone can help me (the character motor is still the same as unity uses). Character controller: Code (CSharp): using UnityEngine; using System.Collections; [RequireComponent (typeof(CharacterController))] public class FirstPersonController : MonoBehaviour { public float runSpeed = 20.0f; public float crchSpeed = 3.0f; public float movementSpeed = 5.0f; public float mouseSensivity = 5.0f; public float jumpSpeed = 4.0f; public bool grounded = false; public float acceleration = 2.0f; public float deceleration = 0.5f; private float curSpeed = 5.0f; private float fallSpeed = 5.0f; private Transform tr; private float dist; // distance to ground float verticalRotation = 0; public float upDownRange = 60.0f; public float verticalVelocity = 0; CharacterController characterController; // Use this for initialization void Start () { Screen.lockCursor = true; characterController = GetComponent<CharacterController>(); tr = transform; CharacterController ch = GetComponent<CharacterController>(); dist = ch.height/2; // calculate distance to ground } void FixedUpdate (){ float vScale = 1.0f; float speed = movementSpeed; curSpeed += acceleration * Time.deltaTime; if (curSpeed > runSpeed) curSpeed = runSpeed; fallSpeed -= deceleration * Time.deltaTime; if (fallSpeed < movementSpeed) fallSpeed = movementSpeed; if (Input.GetKey("c")) { // press C to crouch vScale = 0.5f; movementSpeed = crchSpeed; // slow down when crouching }else{ movementSpeed = 5f; } if ((Input.GetKey(KeyCode.LeftShift)|| Input.GetKey(KeyCode.RightShift))&& characterController.isGrounded) { movementSpeed = curSpeed; }else{ movementSpeed = 5f; } float ultScale = tr.localScale.y; // crouch/stand up smoothly Vector3 tmpScale = tr.localScale; Vector3 tmpPosition = tr.position; tmpScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5 * Time.deltaTime); tr.localScale = tmpScale; tmpPosition.y += dist * (tr.localScale.y - ultScale); // fix vertical position tr.position = tmpPosition; } // Update is called once per frame void Update () { //Rotation float rotLeftRight = Input.GetAxis("Mouse X")* mouseSensivity; transform.Rotate(0, rotLeftRight, 0); verticalRotation -= Input.GetAxis ("Mouse Y") * mouseSensivity; verticalRotation = Mathf.Clamp (verticalRotation, -upDownRange, upDownRange); Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0); //movement float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed; float sideSpeed = Input.GetAxis ("Horizontal") * movementSpeed; verticalVelocity += Physics.gravity.y * Time.deltaTime; //if(characterController.isGrounded && Input.GetButton ("Jump")) { //verticalVelocity = jumpSpeed; //} Vector3 speed = new Vector3( sideSpeed, verticalVelocity, forwardSpeed ); speed = transform.rotation * speed; characterController.Move ( speed * Time.deltaTime ); } } Swimcode: Code (CSharp): using UnityEngine; using System.Collections; public class Swimmer : MonoBehaviour { FirstPersonController fpc; CharacterController cc; // Use this for initialization void Start () { RenderSettings.fog = false; RenderSettings.fogColor = new Color (0.2f, 0.4f, 0.8f, 0.5f); RenderSettings.fogDensity = 0.04f; fpc = gameObject.GetComponent<FirstPersonController> (); cc = gameObject.GetComponent<CharacterController> (); } bool IsUnderwater() { return gameObject.transform.position.y < 14.5396; } // Update is called once per frame void Update () { RenderSettings.fog = IsUnderwater (); if (IsUnderwater ()) { fpc.runSpeed = 4; fpc.movementSpeed = 2; fpc.crchSpeed = 1; if (Input.GetKey( KeyCode.LeftShift)) fpc.verticalVelocity(new Vector3(cc.velocity.x, 3, cc.velocity.z)); } else { fpc.runSpeed = 10; fpc.movementSpeed = 5; fpc.crchSpeed = 3; } } } Thanks in advance