/// <param name="duration">the duration requires at least three times bigger than the application framerate so you can see a shake</param> public static ShakeUtility Shake <T>(GameObject obj, Shake.TargetType targetType, bool delayStart, Vector3 vecDirection, float intensity, int frequency, bool dynamic = false, bool usePause = true, bool once = true, float duration = 0.2f) where T : Shake, new() { ShakeUtility su = obj.GetComponent <ShakeUtility>(); if (su != null) { su.StopShake(); su.OmniShake.Reset(); } else { su = obj.AddComponent <ShakeUtility>(); } if (su.OmniShake == null) { su.OmniShake = new T(); } su.OmniShake.targetType = targetType; su.OmniShake.frequency = frequency; su.OmniShake.originVec = dynamic ? -1000 * Vector3.one : su.OmniShake.GetTargetVec(obj.transform); su.OmniShake.intensity = intensity; su.OmniShake.vecDirection = vecDirection; su.OmniShake.usePause = usePause; su.OmniShake.once = once; su.OmniShake.duration = duration; if (!delayStart) { su.OmniShake.Generate(); su.StartShake(); } return(su); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //ShakeUtility su = ShakeUtility.Shake<CurveShake>(gameObject, Shake.TargetType.Scale, true, Vector3.right, 1f, 30, 3); //CurveShake cs = (CurveShake)su.OmniShake; //cs.maxOffset = new Vector2(1.5f, -0.5f); //cs.curveMode = CurveShake.CurveMode.Smooth; //su.OmniShake.Generate(); //su.StartShake(); ShakeUtility.Shake <RandomShake>(gameObject, Shake.TargetType.Scale, false, Vector3.one, 0.2f, 2, false, true, false, 2); } }