/// <summary> /// Modifies this object to have the specified surface type /// </summary> /// <param name="type"> The type of surface that this surface is being changed to</param> public void applyTextureChange(surfaceType type) { if (type != currentSurfaceType) { switch (type) { case surfaceType.NORMAL: currentPhysicsMaterial.staticFriction = NORMAL_STATIC_FRICTION; currentPhysicsMaterial.dynamicFriction = NORMAL_DYNAMIC_FRICTION; GetComponent <Renderer>().material = normalMaterial; GetComponent <Renderer>().material.mainTexture = normalTexture; break; case surfaceType.ICE: currentPhysicsMaterial.staticFriction = ICY_STATIC_FRICTION; currentPhysicsMaterial.dynamicFriction = ICY_DYNAMIC_FRICTION; GetComponent <Renderer>().material = iceMaterial; GetComponent <Renderer>().material.mainTexture = icyTexture; break; case surfaceType.SANDPAPER: currentPhysicsMaterial.staticFriction = SANDPAPER_STATIC_FRICTION; currentPhysicsMaterial.dynamicFriction = SANDPAPER_DYNAMIC_FRICTION; GetComponent <Renderer>().material = sandMaterial; GetComponent <Renderer>().material.mainTexture = sandPaperTexture; break; } currentSurfaceType = type; GetComponent <MeshCollider>().material = currentPhysicsMaterial; } }
// Start is called before the first frame update void Start() { currentPhysicsMaterial.staticFriction = NORMAL_STATIC_FRICTION; currentPhysicsMaterial.dynamicFriction = NORMAL_DYNAMIC_FRICTION; currentPhysicsMaterial.bounciness = 0; currentSurfaceType = surfaceType.NORMAL; GetComponent <Renderer>().material.mainTexture = normalTexture; }
surfaceType CheckSurfaceType() { surfaceType mySurface = surfaceType.Null; if (Physics.Raycast(transform.position, Vector3.down, out groundHit, 1.05f, groundCheckLayer)) { string matName = groundHit.collider.material.name; switch (matName) { case "Ground (Instance)": mySurface = surfaceType.Ground; break; case "Wood (Instance)": mySurface = surfaceType.Wood; break; case "Stone (Instance)": mySurface = surfaceType.Stone; break; case "Mud (Instance)": mySurface = surfaceType.Mud; break; case "Water (Instance)": mySurface = surfaceType.Water; break; case "Mist (Instance)": mySurface = surfaceType.Mist; break; case "Default (Instance)": mySurface = surfaceType.Ground; break; } } else { mySurface = surfaceType.Null; } return(mySurface); }
void FixedUpdate() { PlayerMovement(); MousePosition(); CharacterRotation(); currentSurface = CheckSurfaceType(); if (movementSpeedBonusTimer > 0) { movementSpeedBonusTimer -= Time.deltaTime; } else { movementSpeedBonusTimer = 0; movementSpeedBonus = 0; } //animator update if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { animator.SetBool("moving", true); } else { animator.SetBool("moving", false); } animator.SetBool("grounded", GroundCheck()); //return to menu if (Input.GetKeyDown(KeyCode.Escape)) { MenuFunctions.instance.LoadScene("scene_mainMenu"); } }